1var result = result1.filter(function (o1) {
2 return result2.some(function (o2) {
3 return o1.id === o2.id; // return the ones with equal id
4 });
5});
6// if you want to be more clever...
7let result = result1.filter(o1 => result2.some(o2 => o1.id === o2.id));
1const equals = (a, b) => JSON.stringify(a) === JSON.stringify(b);
2let arr1 = ['1','2'];
3let arr2 = ['1','2'];
4equals(arr1,arr2)//this return false , if not equal then its return false
1Array.prototype.equals = function(arr2) {
2 return (
3 this.length === arr2.length &&
4 this.every((value, index) => value === arr2[index])
5 );
6};
7
8[1, 2, 3].equals([1, 2, 3]); // true
9[1, 2, 3].equals([3, 6, 4, 2]); // false
1// To compare arrays (or any other object):
2// Simple Array Example:
3const array1 = ['potato', 'banana', 'soup']
4const array2 = ['potato', 'orange', 'soup']
5
6array1 === array2;
7// Returns false due to referential equality
8JSON.stringify(array1) === JSON.stringify(array2);
9// Returns true
10
11
12// Another Example:
13const deepArray1 = [{test: 'dummy'}, [['woo', 'ya'], 'weird']]
14const deepArray2 = [{test: 'dummy'}, [['woo', 'ya'], 'weird']]
15
16deepArray1 === deepArray2;
17// Returns false due to referential equality
18JSON.stringify(deepArray1) === JSON.stringify(deepArray2);
19// Returns true
20
21
1const isEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
2
3// Examples
4isEqual([1, 2, 3], [1, 2, 3]); // true
5isEqual([1, 2, 3], [1, '2', 3]); // false
1const arr1 = [1, 2, 3];
2const arr2 = [1, 3, 3];
3
4if (arr1.length !== arr2.length) return console.log("false");
5for (let i = 0; i < arr1.length; i++) {
6 for (let j = 0; j < arr2.length; j++) {
7 if (arr1[i] === arr2[j]) {
8 console.log("yes match", arr1[i], arr2[j]);
9 continue;
10 }
11 console.log("no match", arr1[i], arr2[j]);
12 }
13}