indexOf method in an object array?

前端 未结 27 2433
别跟我提以往
别跟我提以往 2020-11-22 02:18

What\'s the best method to get the index of an array which contains objects?

Imagine this scenario:

var hello = {
    hello: \'world\',
    foo: \'ba         


        
27条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 02:40

    array.filter(function(item, indx, arr){ return(item.hello === 'stevie'); })[0];
    

    Mind the [0].

    It is proper to use reduce as in Antonio Laguna's answer.

    Apologies for the brevity...

提交回复
热议问题