A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-pullat-method/ below:

Lodash _.pullAt() Method - GeeksforGeeks

Lodash _.pullAt() Method

Last Updated : 02 Sep, 2024

Lodash _.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:

Return Value:

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



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4