Seeking the index of an array within another array in JavaScript, demonstrated as follows:
const piece = [5, 10];
const array = [[5, 10], [5, 11]];
//Using indexOf
console.log(array.indexOf(piece));
//Using findIndex
console.log(array.findIndex(function(element) {
return element == piece;
}));
The expected outcome is for both methods to return a 0, signifying the index at which "piece" exists within the larger array. However, both methods are returning -1.
Any insights into why this discrepancy may be occurring? And suggestions for an alternative approach?
Appreciate it!