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
