Saturday, October 11, 2025
HomeLanguagesJavascriptCollect.js pull() Method

Collect.js pull() Method

The pull() method is used to remove an element from collection by given key and return the pulled element.

Syntax:

collect(array).pull(key)

Parameters: The collect() method takes one argument that is converted into the collection and then pull() method is applied on it. The pull() method holds the key as parameter.

Return Value: This method returns the value of given key.

Below example illustrate the pull() method in collect.js:

Example 1:

Javascript




const collect = require('collect.js');
  
let obj = ['Welcome', 'Geeks', 'GFG', 'neveropen'];
  
const collection = collect(obj);
  
console.log(collection.pull(3));


Output:

neveropen

Example 2:

Javascript




const collect = require('collect.js');
  
let obj = {
    name: 'Rahul',
    dob: '25-10-96',
    section: 'A',
    score: 98,
};
  
const collection = collect(obj);
  
console.log(collection.pull('name'));
console.log(collection.pull('dob'));


Output:

Rahul
25-10-96
RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6719 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6839 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS