I want to get the index of the given value inside a Array using underscore.js.
Here is my case
var array = [{\'id\': 1, \'name\': \'xxx\'},
May be my suggestion will give you advice.
Why do you use callback for indexof method? The signature of indexof in underscore.js is the following:
_.indexOf(array, value, [isSorted])
find could be better for this task:
_.find(array, function(item, index) {
if (item.id == searchValue.id) {
alert(index);
}
});