how to add value to array in javascript code example
Example 1: javascript append to array
var colors=["red","white"];
colors.push("blue");
Example 2: javascript append element to array
var colors= ["red","blue"];
colors.push("yellow");
Example 3: javascript pushing to an array
some_array = ["John", "Sally"];
some_array.push("Mike");
console.log(some_array);
["John", "Sally", "Mike"]
Example 4: pushing element in array in javascript
array = ["hello"]
array.push("world");
Example 5: add array to array javascript
const list1 = ["pepe", "luis", "rua"];
const list2 = ["rojo", "verde", "azul"];
const newList = [...list1, ...list2];
Example 6: javascript array push
let animals = ["dog","cat","tiger"];
animals.pop();
animals.push("elephant");