Tuesday, June 4, 2013

.shift() like .pop() removes an item from an array in JavaScript.

Where .pop() removes the last item, .shift() however removes the first item. Please note that:

routePieces.shift();

 
 

...would be the appropriate way to update routePieces and not

routePieces = routePieces.shift();

 
 

...which behaves badly.

 
 

Addendum 12/14/2018: The variable assignment above will get the item removed by the .shift() operation I think.

No comments:

Post a Comment