Thursday, July 4, 2024
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

Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments