Friday, February 6, 2026
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
32490 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6862 POSTS0 COMMENTS
Nicole Veronica
11985 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12073 POSTS0 COMMENTS
Shaida Kate Naidoo
6995 POSTS0 COMMENTS
Ted Musemwa
7236 POSTS0 COMMENTS
Thapelo Manthata
6946 POSTS0 COMMENTS
Umr Jansen
6931 POSTS0 COMMENTS