add after ary assign assignIn assignInWith assignWith at before bind bindAll bindKey camelCase capitalize castArray ceil chain chunk clamp clone cloneDeep cloneDeepWith cloneWith compact concat conformsTo countBy create curry curryRight debounce deburr defaults defaultsDeep defer delay difference divide drop dropRight each eachRight endsWith entries entriesIn eq escape every extend extendWith fill filter find findIndex findKey findLast findLastIndex findLastKey first flatMap flatMapDeep flatMapDepth flatten flattenDeep flattenDepth flip floor forEach forEachRight forIn forInRight forOwn forOwnRight fromPairs functions functionsIn get groupBy gt gte has hasIn head inRange includes indexOf initial intersection invert invertBy invoke invokeMap isArguments isArray isArrayBuffer isArrayLike isArrayLikeObject isBoolean isBuffer isDate isElement isEmpty isEqual isEqualWith isError isFinite isFunction isInteger isLength isMap isMatch isMatchWith isNaN isNative isNil isNull isNumber isObject isObjectLike isPlainObject isRegExp isSafeInteger isSet isString isSymbol isTypedArray isUndefined isWeakMap isWeakSet join kebabCase keyBy keys keysIn last lastIndexOf lowerCase lowerFirst lt lte map mapKeys mapValues max maxBy mean meanBy memoize merge mergeWith min minBy multiply negate nth omit omitBy once orderBy overArgs pad padEnd padStart parseInt partial partialRight partition pick pickBy pull pullAll pullAllBy pullAllWith pullAt random rearg reduce reduceRight reject remove repeat replace rest result reverse round sample sampleSize set setWith shuffle size slice snakeCase some sortBy sortedIndex sortedIndexOf sortedLastIndex sortedLastIndexOf sortedUniq split spread startCase startsWith subtract sum sumBy tail take takeRight tap template throttle thru toArray toFinite toInteger toLength toLower toNumber toPairs toPairsIn toPlainObject toSafeInteger toString toUpper transform trim trimEnd trimStart truncate unary unescape union uniq uniqBy uniqWith unset unzip unzipWith update updateWith upperCase upperFirst values valuesIn without words wrap wrapperAt wrapperChain wrapperCommit wrapperFlatMap wrapperLodash wrapperNext wrapperPlant wrapperReverse wrapperToIterator wrapperValue xor zip zipObject zipObjectDeep zipWith

Lodash _.pullAt


The lodash _.pullAt method is a convenient utility function that allows developers to easily remove elements from an array based on their indices. This method is particularly useful when dealing with arrays of objects, as it can simplify the process of removing specific objects from the array based on their position.

To use _.pullAt, developers simply need to provide an array of indices to remove, and the method will return a new array containing the removed elements. The original array will be modified to exclude the removed elements.

Here is an example usage of _.pullAt:

const array = ['a', 'b', 'c', 'd'];
const removed = _.pullAt(array, [1, 3]);

console.log(array); // -> ['a', 'c']
console.log(removed); // -> ['b', 'd']

In the above example, we start with an array that contains four elements. We call _.pullAt with an array of indices [1, 3], which correspond to the positions of the elements we want to remove ('b' and 'd'). The method returns a new array removed containing those elements, and the original array has been modified to exclude those elements.

_.pullAt can also be used with arrays of objects. Here is an example:

const array = [
  { id: 1, name: 'Alice'},
  { id: 2, name: 'Bob'},
  { id: 3, name: 'Charlie'}

const removed = _.pullAt(array, [1]);

console.log(array); // -> [{ id: 1, name: 'Alice' }, { id: 3, name: 'Charlie' }]
console.log(removed); // -> [{ id: 2, name: 'Bob' }]

In this example, we have an array of objects. We call _.pullAt with an array containing a single index, 1, which corresponds to the second object in the array ({ id: 2, name: 'Bob' }). The method returns a new array containing that object, and the original array has been modified to exclude it.

One important thing to note about _.pullAt is that it modifies the original array in place. If you want to preserve the original array, you should create a copy of it before calling _.pullAt. For example:

const array = ['a', 'b', 'c', 'd'];
const arrayCopy = [...array];
const removed = _.pullAt(arrayCopy, [1, 3]);

console.log(array); // -> ['a', 'b', 'c', 'd']
console.log(arrayCopy); // -> ['a', 'c']
console.log(removed); // -> ['b', 'd']

In this example, we create a copy of the array using the spread operator ([...array]). We call _.pullAt with the copy, leaving the original array intact.