[JS] findIndex()

양주영·2022년 8월 26일
0

javascript

목록 보기
33/42

Array.prototype.findIndex()

findIndex() 메서드는 주어진 판별 함수를 만족하는 배열의 첫 번째 요소에 대한 인덱스를 반환한다. 만족하는 요소가 없으면 -1을 반환한다.


findIndex()는 파라미터로 함수를 입력받아, 특정 조건을 확인해서 조건에 만족하면 만족하는 원소가 몇 번째인지 알려준다.

select(photoIdx: any) {
      const selectedPhotoIndex = this.list.findIndex((e) => e.idx === photoIdx)
      this.selectImage = this.list[selectedPhotoIndex]
      this.selectImage.numbering = selectedPhotoIndex
    },


참고
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex

profile
뚜벅뚜벅

0개의 댓글