indexOf method in an object array?

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

    Try this:

    console.log(Object.keys({foo:"_0_", bar:"_1_"}).indexOf("bar"));
    

    https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/keys

提交回复
热议问题