élément JS Array Ajouter
array.push(element)
Common Mynah
array.push(element)
const arr = [1, 2, 3, 4];
arr.push(5);
console.log(arr); // [1, 2, 3, 4, 5]
// another way
let arr = [1, 2, 3, 4];
arr = [...arr, 5];
console.log(arr); // [1, 2, 3, 4, 5]
// initialize array
var arr = [
"Hi",
"Hello",
"Bonjour"
];
// append new value to the array
arr.push("Hola");
console.log(arr);
Run code snippet
const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);
const sports = ['Football', 'Tennis']
sports.push('Basketball') // => ['Football', 'Tennis', 'Basketball']
let colors = ["green","blue"]
colors = [...colors,"red"]