Example
Link: http://jsfiddle.net/ewBGt/
var test = [{
"name": "John Doo"
}, {
"name": "Foo Bar"
}]
var find = 'John Doo'
console.log(test.indexOf(find)) // output: -1
console.log(test[find]) // output: undefined
$.each(test, function(index, object) {
if(test[index].name === find)
console.log(test[index]) // problem: this way is slow
})
Problem
In the above example I have an array with objects. I need to find the object that has name = 'John Doo'
My .each
loop is working, but this part will be executed 100 times and test will contain lot more objects. So I think this way will be slow.
The indexOf()
won't work because I cannot search for the name in object.
Question
How can I search for the object with name = 'John Doo'
in my current array?