Something like this
var test = {a: 'a', b: 'b'}; var test2 = {a: 'a', b: 'b'};
var a = [];
a.push(test);
alert($.inArray(test2, a));
Test2 = -1
Test = 0
Why is this? The objects should be identical right? What kind of comparison is it doing?
EDIT:
Clarifying some things. All the answers below are extremely informative. I am using an array to store a runtime pair of values a “page” and a “directory”. These are normally separated unrelated values. I wanted to setup a array of certain pair values and be able to get those two unrelated, form that key pair relationship by creating an object, then searching an array of “allowed” pairs using this method.
I’ll use the custom search function for this. Thanks SO!
You can compare each element:
Or maybe serialize the records and string compare: