how to add new element in array in javascript code example
Example 1: javascript append to array
var colors=["red","white"];
colors.push("blue");
Example 2: append array js
var colors= ["red","blue"];
colors.push("yellow");
Example 3: js add to array
const myArray = ['hello', 'world'];
myArray.push('foo');
myArray.unshift('bar');
myArray.splice(2, 0, 'there');
Example 4: add item to array javascript
const arr1 = [1,2,3]
const newValue = 4
const newData = [...arr1, obj]
Example 5: javascript append to array
arr = [1, 2, 3, 4]
arr.push(5)
arr.unshift(0)