View Single Post
Old 01-20-2013, 09:56 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Array.push() is *NOT* a push-down stack.

It does exactly what you are seeing.

Basically if you do this:
Code:
var ary = [ ];
ary.push("apple");
ary.push("banana");
ary.push("coleslaw");
you get exactly the same result as if you had done
Code:
var ary = [ ];
ary[0] = "apple";
ary[1] = "banana";
ary[2] = "coleslaw";
which is the same you would get if you did
Code:
var ary = ["apple","banana","coleslaw"];
You can argue that the push( ) method of Array is misnamed. But it's way too late to change it now. It is what it is.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Users who have thanked Old Pedant for this post:
DDH (01-20-2013)