본문 바로가기
웹코딩 배우기/· JavaScript

자바스크립트 - 요소 찾기 find, findIndex

by 닐기 2022. 9. 15.

See the Pen find(), findIndex() by nilgi (@nilgi) on CodePen.

 

• find(): 요소 찾기
let gf1 = no1.find(myFunction);
function myFunction(value, index, array) {
    return value > 24;
  }
// 조건에 맞는 첫 번째 요소를 표시

• findIndex(): 요소를 찾고 그 요소의 위치 표시
document.getElementById("gr_fi").innerHTML = no2.findIndex(myFunction);
  function myFunction(value, index, array) {
    return value > 24;
  }
// 조건에 맞는 첫 번째 요소의 위치 표시