Call the .push() method.
// Initialize array
var arr = [
"Hi",
"Hello",
"Bonjour"
];
// Adding a New Element to an Array
arr.push("Hola");
// When adding multiple elements to an array
arr.push("Salut", "Hey");
// Output all elements of an array
for (var i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
Hi
Hello
Bonjour
Hola
Salut
Hey
If you did the same, it would print out like this.
© 2024 OneMinuteCode. All rights reserved.