/**
* Array element Exchange location
* @param {array} arr arrays
* @param {Number} index1 where to add the project
* @param {Number} Index2 delete the location of the project
* Index1 and Index2 are the index values of two arrays, that is, two index values to swap the position of the elements, such as 1,5 is the two elements in the array labeled 1 and 5 exchange positions
*/
function Swaparray (arr, index1, Index2) {
ARR[INDEX1] = Arr.splice (index2, 1, arr[index1]) [0];
return arr;
}
Move up places the current array index index with the next element, moving one after the array
function Zindexup (arr,index,length) {
if (index+1! = length) {
Swaparray (arr, index, index+1);
}else{
Alert (' already pinned, unable to move up ');
}
}
Move down places the current array index index in place of the previous one, moving one in front of the array
function Zindexdown (arr,index,length) {
if (index!= 0) {
Swaparray (arr, index, index-1);
}else{
Alert (' Already in the bottom, unable to move Down ');
}
}
Pinned, moving the current element to the last of the array
function Zindextop (arr,index,length) {
if (index+1! = length) {
First, the current element needs to be moved up several positions, the bottom is moved to the first bit of the array
var movenum = length-1-index;
Loop out the number of times it takes one to move up
for (var i = 0; i<movenum; i++) {
Swaparray (arr, index, index + 1);
index++;
}
}else{
Alert (' already pinned ');
}
}
Bottom, moves the current element to the first bit of the array
function Zindexbottom (arr,index,length) {
if (index!=0) {
First, the current element needs to be moved up several positions, the bottom is moved to the first bit of the array
var movenum = index-0;
Loop out the number of times it takes one to move up
for (var i = 0; i<movenum; i++) {
Swaparray (arr, index, index-1);
index--;
}
}else{
Alert (' Already in the bottom ');
}
}
JS implements array element Exchange location