조건을 충족하는 첫번째 인덱스를 리턴한다.
const array1 = [5, 12, 8, 11, 140, 44];
const isLargeNumber = (element) => element > 13;
console.log(array1.findIndex(isLargeNumber));
// Expected output: 4
조건을 충족하는 요소가 없는 경우는 -1 리턴
const array1 = [5, 12, 8, 11, 5, 2];
const isLargeNumber = (element) => element > 13;
console.log(array1.findIndex(isLargeNumber));
// Expected output: -1
'NOTE' 카테고리의 다른 글
gh-pages을 이용하여 Github Pages에 배포하기 (0) | 2023.03.15 |
---|---|
parseInt(), Number() 의 차이 (0) | 2023.03.02 |
react-helmet (0) | 2023.02.25 |
기존 CRA프로젝트에 typescript 템플릿 추가하기 (0) | 2023.02.22 |
Array.prototype.filter(), Array.prototype.find()의 차이 (0) | 2023.02.16 |