Since the title is not easy to get, I'll provide an example :
var myObject = {
"myArray": [{
"hashKey": "someHashkey1",
"data": "someData1"
}, {
"hashKey": "someHashkey2",
"data": "someData2"
}, {
"hashKey": "someHashkey3",
"data": "someData3"
}]
};
I have "myObject" containing "myArray", and now I would like to efficiently find the index of the object having, for instance, the hashKey "someHashKey2".
I could build my own loop to check all elements in the array, but :
is there a built-in way to do it ? Something like indexOf() ?
is there a npm tool for that kind of need (I work in Node.js)
is there an efficient way to work here ? some bad way to avoid ?
[EDIT :] My efficiency question is due to the fact that I will have to do this operation for basically all the hashKeys. I just found this question which has a "lookup" answer that could help. Still in the process of understanding it all...