Friday, November 21, 2025
HomeLanguagesJavascriptLodash _.pullAt() Method

Lodash _.pullAt() Method

The _.pullAt() method is used to remove the element corresponding to the given address and return an array of removed elements. Syntax:

_.pullAt(array, arrayofIndexes)

Parameters: This method accept two parameters as mentioned above and described below:

  • array: This parameter holds the array that need to be modify.
  • arrayofIndexes: This parameter holds the indexes of elements that need to be removed from array.

Return Value: It returns a new array of removed elements. Example 1: This example removes the given indexed elements from array and returns the array of remaining elements. 

javascript




const _ = require('lodash');
  
let ar = [100, 200, 33, 400, 554]
  
let indexes = [1, 3, 4]
  
let value = _.pullAt(ar, indexes)
  
console.log('Original Array ', ar);
  
console.log('\nRemoved elements array ', value)


Here, const _ = require(‘lodash’) is used to import the lodash library into the file. Output:

Original Array  [ 100, 33 ]

Removed elements array  [ 200, 400, 554 ]

Example 2: This example removes the given indexed elements from array and returns the array of remaining elements. 

javascript




const _ = require('lodash');
  
let ar = ['a', 'b', 'c', 'd', 'e']
  
let indexes = [1, 3]
  
let value = _.pullAt(ar, indexes)
  
console.log('Original Array ', ar);
  
console.log('\nRemoved elements array ', value)


Output:

Original Array  [ 'a', 'c', 'e' ]

Removed elements array  [ 'b', 'd' ]

Example 3: This example removes the given indexed elements from array and returns the array of remaining elements. 

javascript




const _ = require('lodash');
  
let ar = [{'name': 'lodash'}, 
          {'function': 'pullAt'}, 
          {'used on': 'array'}];
  
let indexes = [1, 2]
  
let value = _.pullAt(ar, indexes)
  
console.log('Original Array ', ar);
  
console.log('\nRemoved elements array ', value)


Output:

Original Array  [ { name: 'lodash' } ]

Removed elements array  [ { function: 'pullAt' }, { 'used on': 'array' } ]

Note: This will not work in normal JavaScript because it requires the library lodash to be installed. Reference: https://lodash.com/docs/4.17.15#pullAt

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32405 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6781 POSTS0 COMMENTS
Nicole Veronica
11928 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11996 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7166 POSTS0 COMMENTS
Thapelo Manthata
6862 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS