// Using the .unshift() method
const reverseArray = arr => {
let reversed = [];
for (let i = 0; i < arr.length; i++) {
reversed.unshift(arr[i]);
}
return reversed
}
if we want to reverse order the last element will become the first.How can this method reverse the order when it starts at first index?
unshiftalways adds to the first index, that's how.reversedarray. This produced an array with the elements in reverse order from the original.reversedArray = [...originalArray].reverse()does the job too