What will the Array.unshift() method do?
a) Add one or more elements to the beginning of an array
b) Remove the first element of an array
c) Add one or more elements to the end of an array
d) Sort the elements of an array
Answer:
a) Add one or more elements to the beginning of an array
Explanation:
The Array.unshift()
method adds one or more elements to the beginning of an array and returns the new length of the array.
Example:
let fruits = ["Banana", "Cherry"];
fruits.unshift("Apple");
console.log(fruits); // Output: ["Apple", "Banana", "Cherry"]