Append an Element to Array in JavaScript
In this tutorial, you are given an element and array. You should write a JavaScript program to append the element to array.
Solution
To append given element to an array, use JavaScript array method push(). call push() on the array object and pass the element as argument.
Program
Append item
element to the array fruits
.
let fruits = ['apple', 'banana', 'cherry'];
let item = 'mango';
fruits.push(item);
console.log(fruits);