The JavaScript version of the answer in a related query:
function checkArraysEquality<T>(arr1: T[] | null, arr2: T[] | null): bool {
if (arr1 === arr2) {
return true;
}
if (arr1 == null || arr2 == null || arr1.length !== arr2.length) {
return false;
}
// If you are not concerned about the order of elements inside
// This is a loose comparison. For strict comparison, consider counting each element.
// return arr1.every(item => arr2.some(item)) && arr2.every(item => arr1.some(item));
for (let index = 0; index < arr1.length; ++index) {
if (arr1[index] !== arr2[index]) {
return false;
};
}
return true;
}
Usage in your code:
let items:(string|boolean)[]=['abc','def',true,false,'xyz']
let copiedItems:(string|boolean)[]=['abc','def',true,false,'xyz']
let areAllItemsEqual:boolean = checkArraysEquality(items, copiedItems);