How to mirror an array in Javascript?

Viewed 38

A mirrored array looks like this.

let arr = [1,2,3,4,5]
let mirrored = [1,2,3,4,5,4,3,2,1]

Please help me achieve the result.

1 Answers

I was able to achieve the intended result like this.

let arr = [1,2,3,4,5];
let x = [...arr];
let result =  x.concat(arr.reverse().slice(1,arr.length));
console.log(result);

Related