Splice an array synchronously or asynchronously
$ npm install splice-array --save
const splice = require('splice-array')
const array = [1, 2, 3]
splice(array, (x, i) => i % 2 === 1) // returns [2]
console.log(array) // [2]
const array2 = [1, 2, 3]
splice.p(array2, (x, i) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(i % 2 === 1)
}, 100)
})
})
.then(result => {
console.log(result === array2) // true
console.log(result) // [2]
})
Returns the modified array
Returns Promise
MIT