indexOf method in an object array?

前端 未结 27 2490
别跟我提以往
别跟我提以往 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:28

    In ES2015, this is pretty easy:

    myArray.map(x => x.hello).indexOf('stevie')
    

    or, probably with better performance for larger arrays:

    myArray.findIndex(x => x.hello === 'stevie')
    

提交回复
热议问题