I am adding a String and an array to an already created array myArray
using push(). However, when I print the updated myArray
in the console after pushing(), I only see the String added to myArray
, not the added array, in myArray
‘s content. (The content is seen when I press the little carrot next to the myArray
array in the console.) The added array isn’t being taken account in the length of the updated myArray
either. Why is this?
Note: The added array isn’t shown to be in the updated myArray
, but when I pop() the last element from the updated myArray
, the array that was added (the one of interest) is returned. So it seems to be stored in myArray
but not technically?? What is going on?
My code:
var myArray = [1, 2, 3];
myArray.push('Jacob', ['Brandy', 2]);
console.log(myArray);
var removedValue = myArray.pop();
console.log(removedValue);
Current Output:
Array(5) [ 1, 2, 3, "Jacob", (2) […] ]
0: 1
1: 2
2: 3
3: "Jacob"
length: 4
<prototype>: Array []
Expect:
Array(5) [ 1, 2, 3, "Jacob", (2) […] ]
0: 1
1: 2
2: 3
3: "Jacob"
4: ["Brandy", 2]
length: 5
<prototype>: Array []