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
  • 757
  • 2
  • 10
  • 22

2 Answers2

1

Try this:

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

myArray.push(anotherArray);
myArray.indexOf(anotherArray);  // returns 0
Zychoo
  • 595
  • 2
  • 6
  • 23
1

Try something like this:

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

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