Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Collect.js pull() Method

  • Last Updated : 30 Nov, 2020

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

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

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', 'GeeksforGeeks'];
  
const collection = collect(obj);
  
console.log(collection.pull(3));

Output:

GeeksforGeeks

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
My Personal Notes arrow_drop_up
Recommended Articles
Page :