we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "javascript move last array element to first"
Isabella
10 May 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]