move-element
Move an array element to a given position.
Install
npm install --save --save-exact move-element
Usage
const moveElement =// Say you have an array of fruitsconst fruits = 'Oranges' 'Apples' 'Bananas' 'Pineapples'// And you want to swap the positions of 'Apples' and 'Bananas'// First you make a function that returns true for the element you want to moveconst isApples = x === 'Apples'// Then you call moveElement with the index you want to move the element toconst newArray =// Then newArray will be set to:// ['Oranges', 'Bananas', 'Apples', 'Pineapples']
License
MIT © Thomas Marek