Collect.js whereNull() Method
Last Updated :
29 Jul, 2020
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
Syntax:
whereNull(key if any);
Parameters: It accepts the key of the object.
Returns: It returns the collection object.
Example 1:
Javascript
const collect = require( 'collect.js' );
let obj1 = [1, null , 3, null , 4, 5];
let collection = collect(obj1);
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
const collect = require( 'collect.js' );
let obj1 = [{ "a" : null }, { "a" : 1 },
{ "b" : null }, { "a" : 3 }, { "a" : null }];
let collection = collect(obj1);
let collectionFilter = collection.whereNull( "a" );
console.log( "Original collection is: " ,
collection.all())
console.log( "Filtered collection is: " ,
collectionFilter.all());
|
Output:
Reference: https://collect.js.org/api/whereNull.html
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...