Thursday, November 20, 2025
HomeLanguagesJavascriptCollect.js except() Method

Collect.js except() Method

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', 'neveropen', 'Welcome'];
  
const collection = collect(arr);
  
const remaining_element = collection.except('GFG');
  
console.log(remaining_element);


Output:

Collection { items: [ 'Geeks', 'neveropen', 'Welcome' ] }
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32404 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6776 POSTS0 COMMENTS
Nicole Veronica
11924 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11994 POSTS0 COMMENTS
Shaida Kate Naidoo
6904 POSTS0 COMMENTS
Ted Musemwa
7159 POSTS0 COMMENTS
Thapelo Manthata
6859 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS