how to append an array code example
Example 1: append array js
var colors= ["red","blue"];
colors.push("yellow"); //["red","blue","yellow"]
Example 2: javascript append element to array
var colors= ["red","blue"];
colors.push("yellow");
Example 3: javscript append item from array
let foo = ['oop','plop','copo'];
foo.push("plop");
Example 4: js push array
var array = [];
var element = "anything you want in the array";
array.push(element); // array = [ "anything you want in the array" ]
Example 5: how to append to an array
// initialize array
var arr = [
"Hi",
"Hello",
"Bonjour"
];
// append new value to the array
arr.push("Hola");
console.log(arr);
Example 6: how to append an element to an array in javascript
//Use push() method
//Syntax:
array_name.push(element);
//Example:
let fruits = ["Mango", "Apple"];
//We want to append "Orange" to the array so we will use push() method
fruits.push("Orange");
//There we go, we have successfully appended "Orange" to fruits array!