How To Add Items To An Array in JavaScript

Опубликовано: 06 Октябрь 2024
на канале: Easy Learning
96
4

1) The push() method adds one or more elements to the end of an array and returns the new length of the array. ...
2) The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array: var a = [1, 2, 3]; a.

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

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

console.log(arr);