728x90

✨ testing function의 결과로 나온 array 중 첫 번째 값(value)을 반환하는 build-in method

💻Example Code

const arr = [5, 10, 15, 20, 25];
const found = arr.find(element => element > 10);
const found2 = arr.find(element => element > 5);
console.log(found);
console.log(found2);
view raw find.js hosted with ❤ by GitHub

실행 결과

🧨 DOM에서 원하는 node를 찾고자 할 때 유용하게 사용할 수 있다.

실전 예제

👉 자세한 내용은 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find

 

Array.prototype.find()

The find() method returns the value of the first element in the provided array that satisfies the provided testing function.

developer.mozilla.org

 

'JavaScript > Built-in Method etc.' 카테고리의 다른 글

String.prototype.trim()  (2) 2020.08.10
Array.prototype.splice()  (2) 2020.05.15
String.prototype.charAt()  (0) 2020.02.22
Set (Object)  (0) 2020.02.20
String.prototype.localeCompare()  (0) 2020.02.20

+ Recent posts