프로그래밍 정보공유

findIndex를 이용하여 object array내 원소 위치 탐색하기

student513 2020. 7. 7. 15:03
_findNoticeOrder = () => {
        const notices = this.props.notices
        let order = notices.findIndex( notice => notice.id === this.state.noticeId )
        console.log(this.state.noticeId)
        return order
}
 

Get the index of the object inside an array, matching a condition

I have an array like this: [{prop1:"abc",prop2:"qwe"},{prop1:"bnmb",prop2:"yutu"},{prop1:"zxvz",prop2:"qwrq"},...] How can I get the index of the object that matches a condition, without iteratin...

stackoverflow.com