JavaScript: Rotate the elements left of a given array of integers of length 3
JavaScript Basic: Exercise-70 with Solution
Rotate Elements Left in Array (Length 3)
Write a JavaScript program to rotate the elements left in a given array of integers of length 3.
The program takes an array of three integers and rotates its elements to the left, meaning the first element moves to the end, the second element moves to the first position, and the third element moves to the second position. The modified array is then returned or displayed.
Visual Presentation:

Sample Solution:
JavaScript Code:
Output:
[4,5,3] [-1,2,0] [6,5,7]
Live Demo:
Flowchart:

ES6 Version:
For more Practice: Solve these Related Problems:
- Write a JavaScript program that rotates the elements of a three-element array to the left, moving the first element to the end.
- Write a JavaScript function that cyclically shifts a length-3 array to the left without using built-in rotation functions.
- Write a JavaScript program that verifies an array has exactly three elements before performing a left rotation and returning the new array.
Go to:
PREV : Sum of 3 Elements in Array (Length 3).
NEXT : Check if 1 is First/Last Element in Array.
Improve this sample solution and post your code through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.