As per Mukesh Sharma's response, you are not using the equal operator correctly.
When using ===
, you test if objects themselves to point to the same reference (which is definitely not the case).
You seem to want to test if two arrays (which are also objects with special properties) are equal. In this case, using a simple equality will never work. You have to iterate through all objects in the array, and then, for each object, iterate through all the keys and check if they are similar to the correspondent of the other array.
You can refer to this answer to check how you can compare two objects. The end result should look like this:
// assuming you use ES6
let array1 = [{ a: 1, b: 2 }];
let array2 = [{ a: 1, b: 2 }];
// check if the arrays have different length
if (array1.length !== array2.length) {
// definitely not equal
return false;
}}
let n = array1.length;
for (let i = 0; i < n; i++) {
let res = deepObjCmp(array1[i], array2[i]);
if (!res) {
// at least one object is different
return false;
}
}