Hi I have an array of objects
[
{
outletId: 619734
tleaderId: "3f8be9bf-5920-4d3d-b915-50ca76cb21oo"
},
{
outletId: 619755
tleaderId: "3f8be9bf-5920-4d3d-b915-50ca76cb24ty"
},
{
outletId: 619700
tleaderId: "3f8be9bf-5920-4d3d-b915-50ca76cb2qwe"
}
// and so on...
]
Then I'm creating another object
[
{
outletId: 619734
tleaderId: "3f8be9bf-5920-4d3d-b915-50ca76cb21oo"
}
]
And I want to find if the new created object matches any of the object in the array. I tried this with no luck
$.each(objCollection, function () {
if (this === newObject) {
alert("Already exist!!!");
}
});
Any idea?
Thanks in advance
===operator is only going to work if they're literally the same object. Not just have the same properties, but refer to the same memory address. You'll need a function that compares two objects that you can call.