1

I am most likely overlooking something something pretty basic here, but I have a really hard time figuring out why I get the following behaviour, when looking for a specific array in another array:

myArray.push(["Name", 1, 2]);
myArray.indexOf(["Name", 1, 2]);

Returns -1.. Why can't I find the array that I just pushed?

user2806026
  • 787
  • 3
  • 10
  • 24

2 Answers2

1

Try this:

var myArray = [];
var anotherArray = ["Name", 1, 2];

myArray.push(anotherArray);
myArray.indexOf(anotherArray);  // returns 0
Zychoo
  • 625
  • 2
  • 8
  • 25
1

Try something like this:

var checkArray = ["Name", 1, 2]
var myArray = [];

myArray.push(checkArray);
myArray.indexOf(checkArray);
Kingsthor
  • 182
  • 6