indexOf method in an object array?

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

    I think you can solve it in one line using the map function:

    pos = myArray.map(function(e) { return e.hello; }).indexOf('stevie');
    

提交回复
热议问题