add elements to list javascript code example

Example 1: javascript append to array

var colors=["red","white"];
colors.push("blue");//append 'blue' to colors

Example 2: add item to list javascript

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi"); // Fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];

Example 3: javscript append item from array

let foo = ['oop','plop','copo'];
	foo.push("plop");

Example 4: javascript append element to array

// initialize array
var arr = [
  "Hi",
  "Hello",
  "Bonjour"
];

// append new value to the array
arr.push("Hola");

console.log(arr);

Example 5: javascript append list

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");

Example 6: how to push array

//the array comes here
var numbers = [1, 2, 3, 4];

//here you add another number
numbers.push(5);

//or if you want to do it with words
var words = ["one", "two", "three", "four"];

//then you add a word
words.push("five")

//thanks for reading

Tags:

Java Example