OhLook
0
Q:

javascript append element to array

var colors= ["red","blue"];
	colors.push("yellow"); //["red","blue","yellow"]
24
var colors=["red","white"];
colors.push("blue");//append 'blue' to colors
79
var colors= ["red","blue"];
	colors.push("yellow"); 
41
var a = [1, 2, 3, 4];
a.unshift(0);
a; // => [0, 1, 2, 3, 4]
1
// initialize array
var arr = [
  "Hi",
  "Hello",
  "Bonjour"
];

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

console.log(arr);
3
arr = [1, 2, 3, 4]
arr.push(5) // adds element to end

arr.unshift(0) // adds element to beginning
1
let foo = ['oop','plop','copo'];
	foo.push("plop");
6
var a = [1, 2, 3, 4];
a.unshift(0);
a; // => [0, 1, 2, 3, 4]
0

var fruits = ["Banana", "Orange", "Apple", "Mango"];

fruits.push("Kiwi"); .cut-text { 
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
0

New to Communities?

Join the community