javascript comparing an 2 items in an array code example
Example 1: comparing two arrays in javascript
const arr1 = [1, 2, 3];
const arr2 = [1, 3, 3];
if (arr1.length !== arr2.length) return console.log("false");
for (let i = 0; i < arr1.length; i++) {
for (let j = 0; j < arr2.length; j++) {
if (arr1[i] === arr2[j]) {
console.log("yes match", arr1[i], arr2[j]);
continue;
}
console.log("no match", arr1[i], arr2[j]);
}
}
Example 2: compare between two arrays javascript
const equals = (a, b) => JSON.stringify(a) === JSON.stringify(b);
let arr1 = ['1','2'];
let arr2 = ['1','2'];
equals(arr1,arr2)