json index of property value

后端 未结 6 1391
春和景丽
春和景丽 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:19

    Since there is no index of your data structure by _id, something is going to have to loop over the structure and find an _id value that matches.

    function findId(data, id) {
        for (var i = 0; i < data.length; i++) {
            if (data[i]._id == id) {
                return(data[i]);
            }
        }
    }
    

提交回复
热议问题