Answers for "javascript arary insert at 0"

56

javascript add new array element to start of array

var colors = ["white","blue"];
colors.unshift("red"); //add red to beginning of colors
// colors = ["red","white","blue"]
Posted by: Guest on July-23-2019
2

prepend to array javascript

// Build an array of test data.
var data = [ "X" ];

// Unshift data onto the array. Unshift() prepends elements to
// the beginning of the given array. Note that it can take more
// than one argument. In the output, notice that when unshift()
// takes multiple arguments, they are prepended in a right-to-left
// order (mimicing their appearence in the arguments list).
data.unshift( "A" );
data.unshift( "B", "C" );

// Output resultant array.
console.log( data );
Posted by: Guest on May-12-2020

Code answers related to "javascript arary insert at 0"

Code answers related to "Javascript"

Browse Popular Code Answers by Language