Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript add to array

// Add to the end of array
let colors = ["white","blue"];
colors.push("red");
// ['white','blue','red']

// Add to the beggining of array
let colors = ["white","blue"];
colors.unshift("red");
// ['red','white','blue']

// Adding with spread operator
let colors = ["white","blue"];
colors = [...colors, "red"];
// ['white','blue','red']
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #javascript #add #array
ADD COMMENT
Topic
Name
7+4 =