Saturday, February 7, 2026
HomeLanguagesJavascriptCollect.js reject() Method

Collect.js reject() Method

The reject() method is used to filter the given collection of elements using the given callback function. If the callback function returns true, then the element is removed from the resulting collection, otherwise, it is not removed.

Syntax:

collect(array).reject(callback)

Parameters: The collect() method takes one argument that is converted into the collection and then reject() method is applied to it. The reject() method holds the callback as a parameter.

Return Value: This method returns the filtered elements from the collection.

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

Example 1:

Javascript




const collect = require('collect.js');
  
let obj = ['Geeks', 'GFG', 'neveropen'];
  
const collection = collect(obj);
  
const filtered = collection.reject(
    element => element.length > 4);
  
console.log(filtered.all());


Output:

[ 'GFG' ]

Example 2:

Javascript




const collect = require('collect.js');
  
let obj = [
    {
        name: 'Rahul',
        marks: 88
    },
    {
        name: 'Aditya',
        marks: 78
    },
    {
        name: 'Abhishek',
        marks: 87
    }
];
  
const collection = collect(obj);
  
const filtered = collection.reject(
    element => element.name.length > 5);
  
console.log(filtered.all());


Output:

[ { name: 'Rahul', marks: 88 } ]
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
32492 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6863 POSTS0 COMMENTS
Nicole Veronica
11987 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12079 POSTS0 COMMENTS
Shaida Kate Naidoo
6996 POSTS0 COMMENTS
Ted Musemwa
7239 POSTS0 COMMENTS
Thapelo Manthata
6947 POSTS0 COMMENTS
Umr Jansen
6934 POSTS0 COMMENTS