js add in array code example
Example 1: javascript append to array
var colors=["red","white"];
colors.push("blue");
Example 2: js add item to array
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
Example 3: add item to list javascript
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
Example 4: js add to array
const myArray = ['hello', 'world'];
myArray.push('foo');
myArray.unshift('bar');
myArray.splice(2, 0, 'there');
Example 5: js add to array
let arr = [1, 2, 3, 4];
arr = [...arr, 5, 6, 7];
console.log(arr);
Example 6: how to add to an array js
var colors = ["blue", "red"];
colors.push("black")