You can do like, remove the elements from your index
to length
of the array and push it to start of the same array
const array = [1, 2, 3, 4, 5];
const index = 2;
array.unshift(...array.splice(index))
console.log(array)
You could get the index of the current dot value. Then create an array with 2 iterations of the original array using [...array, ...array]
. For the given array, it will look like [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
. Then use slice
to get array.length
items starting from index
function getRotation(array, value) {
const index = array.indexOf(value);
return [...array, ...array].slice(index, index + array.length)
}
console.log(getRotation([1, 2, 3, 4, 5], 3))
console.log(getRotation([1, 2, 3, 4, 5], 5))
I have a Rails project where a newly added javascript file (plotly.min.js) is causing rake assets:precompile to hang indefinitely in production mode only. Since the problem is related to javascript ...
I have a Rails project where a newly added javascript file (plotly.min.js) is causing rake assets:precompile to hang indefinitely in production mode only. Since the problem is related to javascript ...
I have the following state. state = { friends: { nickNames: ['Polly', 'P', 'Pau'], ... here more k:v }, } } And I want to update nickNames array with a value coming from an ...
I have the following state. state = { friends: { nickNames: ['Polly', 'P', 'Pau'], ... here more k:v }, } } And I want to update nickNames array with a value coming from an ...
I have setup ionic push for Android and IOS, the android version works great, but the IOS doesn't. I have setup the provisioning and certificate files on IOS and they seem to be fine. Also, the ...
I have setup ionic push for Android and IOS, the android version works great, but the IOS doesn't. I have setup the provisioning and certificate files on IOS and they seem to be fine. Also, the ...
Currently, I am facing one issue related to angularjs directive. I want to send outlet object from directive1 to directive2. Both directives having same controller scope. I tried with emitting event ...
Currently, I am facing one issue related to angularjs directive. I want to send outlet object from directive1 to directive2. Both directives having same controller scope. I tried with emitting event ...