Skip to content

Instantly share code, notes, and snippets.

@croucha
Forked from kjantzer/underscore.move.js
Created November 23, 2016 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save croucha/1a5be2d1d925128752ad2384ad3ab36c to your computer and use it in GitHub Desktop.
Save croucha/1a5be2d1d925128752ad2384ad3ab36c 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