javascript how to move around array code example
Example 1: how to move an element of an array in javascript
function moveElement(array,initialIndex,finalIndex) {
array.splice(finalIndex,0,array.splice(initialIndex,1)[0])
console.log(array);
return array;
}
// Coded By Bilal
Example 2: javascript move element in array
function arrayMove(arr, fromIndex, toIndex) {
var element = arr[fromIndex];
arr.splice(fromIndex, 1);
arr.splice(toIndex, 0, element);
}