I'm learning Javascript and would like to understand why indexOf isn't finding the array within the searched array. (An explanation, theory etc. is the goal for this one, no alternative code or other solutions are needed)
In looking for the array [1, 2] within the array "arr" - why does indexOf not see the array?
Does this have to do with values vs.
const o = { name: "Ethan" };
const arr = [1, 5, "a", o, true, 5, [1, 2], "9"];
console.log(arr.indexOf([1, 2])); //returns -1 expected 1
Expected a return of 1, instead received -1. Why? Anyone able to share the details/theory/computer science aspect of why this is the case?
The answer at: indexOf( object) in javascript addresses objects, not arrays
The answer at: Looking for a good clear explanation for why this doesn't work addresses functions and for loops, not the indexOf method
The answer at: indexOf method in an object array? addresses objects and offers solutions to change how its being done, however I don't see an explanation as to why two arrays that appear to be identical are not being identified as being identical.
The reference of: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Using_the_Equality_Operators addresses comparison operators - and perhaps the answer lies within the realm of strict equality. And this may be where the lack of understanding on my part is. Is the [1, 2] that is being searched for somehow being construed as different than the one that is in the array 'arr' ?
The reference of: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf#Description addresses indexOf but doesn't appear to share any guidance on an array within another array. (Jagged array?)
I'm new to Javascript (as you can tell) and am looking to understand in detail why and/or how in the example the search for [1, 2] doesn't match the element of the arr array that is also [1, 2]