How can I make a reversed copy of an array using .reverse()
? I can't wrap my head around this.
This is my function:
function flipArray(inputArray){
let origArray = inputArray;
let flippedArray = origArray.reverse();
console.log(inputArray);
console.log(origArray);
console.log(flippedArray);
}
flipArray([1,2,3]);
I would expect this...
[1, 2, 3]
[1, 2, 3]
[3, 2, 1]
or this...
[1, 2, 3]
[3, 2, 1]
[3, 2, 1]
but this is what I get...
[3, 2, 1]
[3, 2, 1]
[3, 2, 1]
Why does even inputArray get reversed? Is there another way to do this apart from a for
loop?