반응형
JavaScript array에는 유용한 함수들이 많습니다.
자세한 내용은 여기를 참고하세요.
find()
: find 메서드는 호출된 배열의 모든 element를 대상으로 인자로 작성된 함수를 만족하는 첫번째 element값을 반환합니다.
const sourceArray = [1, 2, 3, 4, 5];
const foundValue = sourceArray.find(x => x > 3);
// 출력값: 4
console.log(foundValue);
findIdex()
: findIndex 메서드는 호출된 배열의 모든 element를 대상으로 인자로 작성된 함수를 만족하는 첫번째 element의 index를 반환합니다.
const sourceArray = [1, 2, 3, 4, 5];
const foundIndex = sourceArray.findIndex(x => x > 3);
// 출력값: 3
console.log(foundIndex);
반응형
'WEB > JS|Node.js' 카테고리의 다른 글
JS Array functions (4) - concat() (0) | 2022.08.28 |
---|---|
JS Array functions (3) - slice(), splice() (0) | 2022.08.28 |
JS Array functions (1) - map(), filter() (0) | 2022.08.28 |
Let & Const (0) | 2022.08.25 |
ES6 Arrow functions (1) | 2022.08.25 |