📜  Collect.js whereNotIn() 方法

📅  最后修改于: 2022-05-13 01:56:25.037000             🧑  作者: Mango

Collect.js whereNotIn() 方法

collect.js 中的whereNotIn()方法用于根据键和值过滤给定集合中的元素。如果找到特定的键值集,则将其过滤掉。

安装:

  • 在 NodeJs 中:
    npm install collect.js
  • collect.js 的 CDN

句法:

whereNotIn(key, array_value);

参数:

  • key:要删除其值的键。
  • array_value:要删除键的值数组。

返回值:返回对象。

示例 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());


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());


输出:

示例 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());

输出:

参考: https://collect.js.org/api/whereNotIn.html