move first element to last javascript

Solutions on MaxInterview for move first element to last javascript by the best coders in the world

showing results for - "move first element to last javascript"
Regina
23 Aug 2019
1let arr1 = [1, 2, 3, 4, 5]
2let arr2 = [1, 2, 3, 4 ,5]
3// first to the last
4arr1.push(arr1.shift()) // [2, 3, 4, 5, 1]
5
6// last to the first
7arr2.unshift(arr2.pop()) // [5, 1, 2, 3, 4]
Lila
28 Jan 2020
1function shiftElementToLastPlace(array){
2  let arr = [...array]
3  arr.push(arr.shift())
4  return arr
5}