Open In App

Collect.js except() Method

Last Updated : 25 Nov, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The except() method is used to return all items in the given collection except the specified keys.

Syntax:

collect(array).except(key)

Parameters: The collect() method takes one argument that is converted into the collection and then except() method is applied on it. The except() method takes one parameter as key which you want to remove from given collection.

Return Value: This method returns the collection items except the given keys items.

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

Example 1:

Javascript




const collect = require('collect.js');
  
const arr = [2, 4, 5, 6, 8, 9, 10];
  
const collection = collect(arr);
  
const remaining_element = 
    collection.except(5, 7, 9, 10, 12);
  
console.log(remaining_element);


Output:

Collection { items: [ 2, 4, 6, 8 ] }

Example 2:

Javascript




const collect = require('collect.js');
  
const arr = ['Geeks', 'GFG', 'GeeksforGeeks', 'Welcome'];
  
const collection = collect(arr);
  
const remaining_element = collection.except('GFG');
  
console.log(remaining_element);


Output:

Collection { items: [ 'Geeks', 'GeeksforGeeks', 'Welcome' ] }

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads