收集.js | whereNotBetween()函数
whereNotBetween()函数用于过滤不在指定范围内的输入。在 JavaScript 中,首先将数组转换为集合,然后将函数应用于集合。
句法:
data.whereNotBetween(key, [range]);
参数:该函数接受上面提到的两个参数,如下所述:
- key:此参数保存定义该键值的键名。
- range:此参数保存指定的范围
返回值:返回不在该范围内的过滤集合。 下面的示例说明了 collect.js 中的whereNotBetween()函数: 输出: 示例 2: 输出: 参考: https ://collect.js.org/api/whereNotBetween.html
示例 1:在此示例中,我们获取一个集合,然后使用whereNotBetween()方法指定键和值范围,检查值并返回不在范围内的值。Javascript
// It is used to import collect.js library
const collect = require('collect.js');
const input= collect([
{ fruits: 'Apple', price: 200 },
{ fruits: 'Banana', price: 80 },
{ fruits: 'Papaya', price: 150 },
{ fruits: 'Grapes', price: 30 },
{ fruits: 'Cherry', price: 100 },
]);
const output = input.whereNotBetween('price', [100, 200]);
console.log(output.all());
Javascript
// It is used to import collect.js library
const collect = require('collect.js');
const input= collect([
{ quantity: 'Flour', price: 150 },
{ quantity: 'Rice', price: 100 },
{ quantity: 'Vegetables', price: 80 },
{ quantity: 'Fruits', price: 90 },
{ quantity: 'Pulses', price: 200 },
]);
const output = input.whereNotBetween('price', [90, 200]);
console.log(output.all());
[ { fruits: 'Banana', price: 80 },
{ fruits: 'Grapes', price: 30 } ]
Javascript
// It is used to import collect.js library
const collect = require('collect.js');
const input= collect([
{ quantity: 'Flour', price: 150 },
{ quantity: 'Rice', price: 100 },
{ quantity: 'Vegetables', price: 80 },
{ quantity: 'Fruits', price: 90 },
{ quantity: 'Pulses', price: 200 },
]);
const output = input.whereNotBetween('price', [90, 200]);
console.log(output.all());
[ { quantity: 'Vegetables', price: 80} ]