Skip to content

Instantly share code, notes, and snippets.

@helloncanella
Forked from kjantzer/underscore.move.js
Created April 2, 2016 03:09
Show Gist options
  • Save helloncanella/5702da6df2a97987078edeea76838ae7 to your computer and use it in GitHub Desktop.
Save helloncanella/5702da6df2a97987078edeea76838ae7 to your computer and use it in GitHub Desktop.
Underscore.js Mixin: Move - takes array and moves item at index and moves to another index; great for use with jQuery.sortable()
/*
_.move - takes array and moves item at index and moves to another index; great for use with jQuery.sortable()
*/
_.mixin({
move: function (array, fromIndex, toIndex) {
array.splice(toIndex, 0, array.splice(fromIndex, 1)[0] );
return array;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment