Is there a more efficient way to determine if two arrays have the same values in JavaScript?
The current method I am using is functional but quite lengthy. Here is how I am checking:
let arraysAreDifferent = false;
array1.forEach(item => {
if (!array2.includes(item)) {
arraysAreDifferent = true;
}
});
array2.forEach(item => {
if (!array1.includes(item)) {
arraysAreDifferent = true;
}
});