This seems like a pretty basic question so I am surprised that I am coming across it now.
var myArray = ['Manchester', 'London', 'Liverpool', 'Birmingham', 'Leeds', 'Carlisle']; var myNewArray = myArray.push('Lusaka'); myArray //result: (10) ["Manchester", "London", "Liverpool", "Birmingham", "Leeds", "Carlisle", "Bradford", "Brighton", "Bristol", "Lusaka"] myNewArray //result: 10
It’s that last bit of code that I am confused about. Why is
myNewArray equal to
length…? And not equal to an
array (i.e. the same array as
myArray, in this case?)
I am willing to accept this if that’s just the way arrays work but was anyone else confused when they first cam across this…?