What\'s the best method to get the index of an array which contains objects?
Imagine this scenario:
var hello = { hello: \'world\', foo: \'ba
You can simply use
const someId = 2; const array = [{id:1}, {id:2}, {id:3}]; const index = array.reduce((i, item, index) => item.id === someId ? index : i, -1); alert('someId ' + someId + ' is at index ' + index);
No underscore, no for, just a reduce.