Move an item in an array
LoDash issue is here. Give it a 👍 if you want to see it added to Lodash.
- Install the package via NPM
npm install lodash-move
or via Yarn
yarn add lodash-move
- Import it into your project:
// Node.JS
const move = require('lodash-move')
// ES6+
import move from 'lodash-move'
- Use it!
move(array, fromIndex, toIndex)
move(['a', 'b', 'c'], 2, 0)
// -> ['c', 'a', 'b']
move([{name: 'Fred'}, {name: 'Barney'}, {name: 'Wilma'}, {name: 'Betty'}], 2, 1)
// -> [{name: 'Fred'}, {name: 'Wilma'}, {name: 'Barney'}, {name: 'Betty'}]