Basically, in able to compare two arrays, first, we need to sort the array which will give the accurate result:
const array2Sorted = array2.slice().sort();
array1.length === array2.length && array1.slice().sort().every(function(value, index) {
return value === array2Sorted[index];
});
This will first sort the array and then it gives the output as true.
I hope this will help.
Want to become a Java Expert? Join Java Training now!!
Want to know more about Java? Watch this video on Java Course | Java Tutorial for Beginners | Java Training: