add something to the start of an array with unshift

unshift is the opposite of push where push adds to the end of an array unshift will add to the start of the array.

Javascript

var my_array = [ ["dog", 2],["fish", 3] ];
my_array.unshift(["cat", 1]);
console.log("the array: "+my_array);

Demo

Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹