Open In App

Collect.js whereNotIn() Method

Improve
Improve
Like Article
Like
Save
Share
Report

The whereNotIn() method in collect.js is used to filter the elements from the given collection on the basis of key and value. If particular set of key-value is found then it is filtered out.

Installation:

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

Syntax:

whereNotIn(key, array_value);

Parameters:

  • key: The key whose value is to be removed.
  • array_value: The array of values that key is to be removed.

Return Value: It returns the object.

Example 1:

Javascript




// Importing the collect.js module.
const collect = require('collect.js');
let obj1 = [
    { "a": 1 },
    { "a": 2 },
    { "a": 3 },
    { "a": 4 },
    { "b": 5 }
]
  
// Making a collection
let collection = collect(obj1);
  
// Using whereNotIn() method to return
// a collection not having value 2, 4
// For key "a"
let collectionFilter = collection
            .whereNotIn("a", [2, 4]);
  
console.log("Original collection is: ",
            collection.all())
              
console.log("Filtered collection is: "
            collectionFilter.all());


Output:

Example 2:

Javascript




// Importing the collect.js module.
const collect = require('collect.js');
  
let obj1 = [
    { "b": 1 },
    { "c": 2 },
    { "b": 3 },
    { "b": 4 },
    { "b": 5 },
    { "c": 11 },
    { "c": 12 },
]
  
// Making a collection
let collection = collect(obj1);
  
// Using whereNotIn() method to return 
// a collection not having value 1, 2, 4
// For key "b"
let collectionFilter = 
    collection.whereNotIn("b", [1, 2, 4]);
  
collectionFilter = 
    collection.whereNotIn("c", [11]);
  
console.log("Original collection is: "
    collection.all());
  
console.log("The output will not contain "
        + "value of 1, 2, 4 for key \"b\""
        + " and value of 11 for key \"c\"");
  
console.log("Filtered collection is: "
        collectionFilter.all());


Output:

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



Last Updated : 29 Jul, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads