Skip to content
Related Articles

Related Articles

Improve Article

Collect.js except() Method

  • Last Updated : 25 Nov, 2020
Geek Week

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' ] }

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!

My Personal Notes arrow_drop_up
Recommended Articles
Page :