DEV Community

Discussion on: Get last element of array in JavsScript

Collapse
 
meirlamdan profile image
meirlamdan • Edited

what you wrote at the end of the post, is not true.
It will not help to copy the array, because it only creates a reference to that array itself
Instead it is possible as follows

let myArray2 = [...myArr]
let last = myArr.pop()
Enter fullscreen mode Exit fullscreen mode