ADD ELEMENT TO AN ARRAY code example
Example 1: java insert array
int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int newarr[] = new int[maxSize];
newarr[pos] = n;
for (i = 0; i < maxSize; i++) { newarr[i] = arr[i]; }
Example 2: javascript append to array
var colors=["red","white"];
colors.push("blue");
Example 3: javascript pushing to an array
some_array = ["John", "Sally"];
some_array.push("Mike");
console.log(some_array);
["John", "Sally", "Mike"]
Example 4: js add item to array
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
Example 5: pushing to an array
array = ["hello"]
array.push("world");
console.log(array);
["hello", "world"]
Example 6: add array to array javascript
const list1 = ["pepe", "luis", "rua"];
const list2 = ["rojo", "verde", "azul"];
const newList = [...list1, ...list2];