add values to an array javascript code example
Example 1: javascript insert item into array
var colors=["red","blue"];
var index=1;
colors.splice(index, 0, "white");
Example 2: append array js
var colors= ["red","blue"];
colors.push("yellow");
Example 3: how to push an element into an array in javascript
var arr = [
"Hi",
"Hello",
"Bonjour"
];
arr.push("Hola");
console.log(arr);
Example 4: how to make and add to an array in javascript
var arrayExample = [53,'Hello World!'];
console.log(arrayExample)
[53,'Hello World!']
arrayExample.push(true);
console.log(arrayExample);
[53,'Hello World!',true];