append to js array code example

Example 1: javascript append to array

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

Example 2: javascript append array to array

const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);

Example 3: javascript append element to array

var colors= ["red","blue"];
	colors.push("yellow");

Example 4: add item to list javascript

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

Example 5: js add element to array

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

fruits.push("Banana");

Example 6: c# append array

List<int> termsList = new List<int>();
for (int runs = 0; runs < 400; runs++)
{
    termsList.Add(value);
}

// You can convert it back to an array if you would like to
int[] terms = termsList.ToArray();

Tags:

Java Example