1function moveArrayItemToNewIndex(arr, old_index, new_index) {
2 if (new_index >= arr.length) {
3 var k = new_index - arr.length + 1;
4 while (k--) {
5 arr.push(undefined);
6 }
7 }
8 arr.splice(new_index, 0, arr.splice(old_index, 1)[0]);
9 return arr;
10};
11
12//move index 1(b) to index 2(c)
13console.log(moveArrayItemToNewIndex(["a","b","c","d"], 1, 2)); // returns ["a", "c", "b", "d"]