Collect.js whereNull() Method Last Updated : 29 Jul, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 Comment More infoAdvertise with us Next Article Collect.js only() Method T tarun007 Follow Improve Article Tags : JavaScript Web Technologies Collect.js Similar Reads Collect.js when() Method The when() method is used to execute the given callback when the first argument given to the method evaluates to true. Syntax: collect.when() Parameters: The collect() method takes one argument that is converted into the collection and then when() method is applied on it. Return Value: This method r 1 min read Collect.js pull() Method The pull() method is used to remove an element from collection by given key and return the pulled element. Syntax: collect(array).pull(key) Parameters: The collect() method takes one argument that is converted into the collection and then pull() method is applied on it. The pull() method holds the k 1 min read Collect.js only() Method The only() method is used to return the items from the given collection with the specified keys. It takes the key as a parameter and returns the item mapped with that key. Syntax: collect(array).only(key)Parameters: The collect() method takes one argument that is converted into the collection and th 2 min read Collect.js reduce() Method The reduce() method is used to reduce the collection elements into a single value according to the given callback. It works by passing the result of each iteration to the next one resulting in a single value in the end. Syntax: collect(array).reduce(callback) Parameters: The collect() method takes o 1 min read Collect.js replace() Method The replace() method is used to replace the elements of the original collection that match the given string or numeric keys. If the key given in the object matches with a key in the collection, then its value is replaced, otherwise, if the key does not match, then it is added to the collection. Synt 1 min read Collect.js sum() Method The sum() method in collect.js is used to return the sum of all the items in the given collection. Syntax: collect(array).sum() Parameters: The collect() method takes one argument that is converted into the collection and then sum() method is applied on it. Return Value: This method returns the sum 1 min read Like