how to use the pullat function from lodash in javascript

The pullAt() function from lodash is used to remove elements from an array and return them in a new array. It takes an array of indices at which to remove the elements.

Here is an example:

index.tsx
const _ = require('lodash');

const myArray = ['apple', 'banana', 'orange', 'pear', 'kiwi'];

const removedElements = _.pullAt(myArray, 1, 3);

console.log(myArray); // Output: ['apple', 'orange', 'kiwi']
console.log(removedElements); // Output: ['banana', 'pear']
265 chars
9 lines

In this example, the pullAt() function is used to remove the elements at indices 1 and 3 from the myArray array. The removed elements are returned in the removedElements array. The original myArray array is modified to contain only the elements that were not removed.

gistlibby LogSnag