json index of property value

后端 未结 6 1376
春和景丽
春和景丽 2020-12-18 08:27

I need to get the index of the json object in an array whose by the objects id

here is the example code

var list = [ { _id: \'4dd822c5e8a6c42aa7000         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-18 09:20

    You can try Array.prototype.map, based on your example it will be:

    var index = list.map(function(e) { return e._id; }).indexOf('4dd822c5e8a6c42aa70000ad');
    

    Array.prototype.map is not available on IE7 or IE8. ES5 Compatibility

提交回复
热议问题