I\'m having a hard time figuring out how to move an array element. For example, given the following:
var arr = [ \'a\', \'b\', \'c\', \'d\', \'e\']; <
var arr = [ \'a\', \'b\', \'c\', \'d\', \'e\'];
I like this way. It's concise and it works.
function arraymove(arr, fromIndex, toIndex) { var element = arr[fromIndex]; arr.splice(fromIndex, 1); arr.splice(toIndex, 0, element); }
Note: always remember to check your array bounds.
Run Snippet in jsFiddle