Friday, July 3, 2026
HomeLanguagesJavascriptCollect.js whereNull() Method

Collect.js whereNull() Method

The whereNull() method in collect.js is used to filter the values from a collection that is null.

Installation:

  • In NodeJs:
    npm install collect.js
  • CDN for collect.js
    <script src="https://cdnjs.com/libraries/collect.js"></script>

Syntax:

whereNull(key if any);

Parameters: It accepts the key of the object.

Returns: It returns the collection object.

Example 1:

Javascript




// Importing the collect.js module.
const collect = require('collect.js');
let obj1 = [1, null, 3, null, 4, 5];
  
// Making a collection
let collection = collect(obj1);
  
// Filtering the null values;
let collectionFilter = collection.whereNull();
console.log("Original collection is: ", collection)
console.log("Filtered collection is: ", collectionFilter);


Output:

Example 2: Using objects having null values.

Javascript




// Importing the collect.js module.
const collect = require('collect.js');
let obj1 = [{ "a": null }, { "a": 1 }, 
    { "b": null }, { "a": 3 }, { "a": null }];
  
// Making a collection
let collection = collect(obj1);
  
// Filtering the null values;
let collectionFilter = collection.whereNull("a");
  
// Printing the original collection
console.log("Original collection is: ", 
        collection.all())
console.log("Filtered collection is: ", 
        collectionFilter.all());


Output:

Reference: https://collect.js.org/api/whereNull.html

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

2 COMMENTS

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12015 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6966 POSTS0 COMMENTS