Ask coding questions

← Back to all posts
How do you rotate an array?how do you rotate an array how do you rotate an array
KrishanParmar (0)

how do you rotate an array how do you rotate an array how do you rotate an array how do you rotate an array how do you rotate an array how do you rotate an array

Commentshotnewtop
vedprad1 (691)

In javascript:

var arr = [1, 2, 3, 4, 5];
var temp = [];
for (var i = arr.length - 1; i >= 0; i--) {
  temp.push(arr[i]);
}
arr = temp;

If this answers your question, please check the checkmark on the left side of this message. Thanks and Good Luck!

mwilki7 (144)

first you assign temp = array[0], set every array[i] = array[i+1] in array finally and set arr[arr.length - 1] = temp first you assign temp = array[0], set every array[i] = array[i+1] in array finally and set arr[arr.length - 1] = temp first you assign temp = array[0], set every array[i] = array[i+1] in array finally and set arr[arr.length - 1] = temp first you assign temp = array[0], set every array[i] = array[i+1] in array finally and set arr[arr.length - 1] = temp first you assign temp = array[0], set every array[i] = array[i+1] in array finally and set arr[arr.length - 1] = temp first you assign temp = array[0], set every array[i] = array[i+1] in array finally and set arr[arr.length - 1] = temp

mwilki7 (144)

@ash15khng i think i missed a few from the title