+ 2
Weird Array Problem
I have the following code: var possibilities = [["X"],["O"],["e"]]; var newPossibilities = []; for (var i=0; i<3; i++) { for (var j=0; j<possibilities.length; j++) { newPossibilities.push(possibilities[j]); } } //newPossibilities is now [["X"],["O"],["e"],["X"],["O"],["e"],["X"],["O"],["e"]]; newPossibilities[0].push("A"); console.log(newPossibilities); //output: [["X", "A"],["O"],["e"],["X", "A"],["O"],["e"],["X", "A"],["O"],["e"]] I'm wondering why the output is [["X", "A"],["O"],["e"],["X", "A"],["O"],["e"],["X", "A"],["O"],["e"]] and not [["X", "A"],["O"],["e"],["X"],["O"],["e"],["X"],["O"],["e"]]. Can someone help me?
1 Respuesta
+ 2
I found the solution here:
https://stackoverflow.com/questions/13565223/strange-array-push-in-js