Collect.js | forget() Function
Last Updated :
28 Nov, 2022
The forget() function as the name suggest forgets/remove an item from the collection using its key. In JavaScript, the array is first converted to a collection and then the function is applied to the collection.
Syntax:
data.forget('key')
Parameters: This function accept a single parameter as mentioned above and described below:
- Key: This parameter holds the key name that define the value of that key.
Return value: Return the collection except the key’s value that was mentioned.
Below examples illustrate the forget() function in collect.js
Example 1: Here in this example, we take a collection and then using the forget() function we return the collection without the key element we forget.
Javascript
const collect = require( 'collect.js' );
const collection = collect({
name: 'Jhon' ,
Roll: 7,
});
collection.forget( 'Roll' );
console.log(collection.all());
|
Output:
{ name: 'Jhon' }
Example 2: Same thing we have done here as above example.
Python3
/ / It is used to import collect.js library
const collect = require( 'collect.js' );
const collection = collect({
Address : '253 Street , California' ,
pincode : '0987'
});
collection.forget( 'Address' );
console.log(collection. all ());
|
Output:
{ pincode: '0987' }
References: https://collect.js.org/api/forget.html
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...