How to shift array elements to right by one position in TypeScript

1 Answer

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

 



answered Sep 12, 2022 by avibootz
...