add data in array javascript code example
Example 1: javascript append to array
var colors=["red","white"];
colors.push("blue");//append 'blue' to colors
Example 2: javascript append element to array
var colors= ["red","blue"];
colors.push("yellow");
Example 3: how to add a new item in an array in javascript
let array = ["Chicago", "Los Angeles", "Calgary", "Seattle", ]
// print the array
console.log(array)
//Adding a new item in an array without touching the actual array
array.push('New Item') < variable_name > .push( < What you want to add > )
//How many items does the array have?
console.log("This array has", array.length, "things in it")
Example 4: add value to array javascript
var fruits = ["222", "vvvv", "eee", "eeee"];
fruits.push("Kiwi");
Example 5: js push array
var array = [];
var element = "anything you want in the array";
array.push(element); // array = [ "anything you want in the array" ]
Example 6: how to insert a value into an array javascript
var list = ["foo", "bar"];
list.push("baz");
["foo", "bar", "baz"] // result