Rotate array element in JavaScript

  1. shift()
let items_list = [1,2,3,4,5,6,7];
console.log("Original Array", items_list);
let shiftResult = items_list.shift();
console.log("shiftResult", shiftResult);
console.log("New Array", items_list);
shift() output
let items_list = [1,2,3,4,5,6,7];
console.log("Original Array", items_list);
let popResult = items_list.pop();
console.log("popResult", popResult);
console.log("New Array", items_list);
pop() output
let items_list = [1,2,3,4,5,6,7];
console.log("Original Array", items_list);
items_list.push(100);
console.log("New Array", items_list);
push() output
let items_list = [1,2,3,4,5,6,7];
console.log("Original Array", items_list);
items_list.unshift(100);
console.log("New Array", items_list);
unshift() output
let items_list = [1,2,3,4,5,6,7];
console.log("Original Array", items_list);
let shiftResult = items_list.shift();
items_list.push(shiftResult);
console.log("New Array", items_list);
Array element rotates to the left side
let items_list = [1,2,3,4,5,6,7];
console.log("Original Array", items_list);
let popResult = items_list.pop()
items_list.unshift(popResult);
console.log("New Array", items_list);
Array element rotates to the right side

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store