How to shift array elements to right by one position in Node.js

1 Answer

0 votes
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
 
arr.unshift(arr.pop());
 
console.log(arr);
 
 
 
 
/*
run:
 
[ 10, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]

*/

 



answered Sep 12, 2022 by avibootz
...