Browse - Programming Tips - How can I prepend (add at the start) an element at the start of a javaScript array?

Date: 2016apr17
Language: javaScript
Keywords: append

Q.  How can I prepend (add at the start) an element at the start of a javaScript array?

A.  Use unshift() like this:

var a = [ 'three', 'four', 'five' ]; a.unshift(['one', 'two']); // prepend an array at the start a.unshift('zero'); // prepend just one element