Question – How to Append an Item to Array in JavaScript. How do I append any element to end of the existing Array in JavaScript? How to push element to array in JavaScript?
This tutorial uses javascript push() function to insert or append a new element to end of the Array.
Advertisement
JavaScript – Append Element to Array
The following example creates an initial array with two elements (as “black”,”blue”). After that use javascript push() function to append new element (“white”) to the array.
1 2 3 4 5 | var colors = ["black", "blue"]; colors.push("white"); //View final array console.log(colors); |
Output:
[ 'black', 'blue', 'white' ]
1 Comment
Very simple and yet so useful!
Thank you!