Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Filter 使用lodash过滤对象特性_Filter_Lodash - Fatal编程技术网

Filter 使用lodash过滤对象特性

Filter 使用lodash过滤对象特性,filter,lodash,Filter,Lodash,我正在尝试使用u.filter属性筛选数组。我想使用matchesProperty速记,但不想直接进行比较 这项工作: .每个(.filter(this.cross,['len',3]),dostuff) 但是如果我想过滤小于9的值,我需要使用一个函数: .each(.filter)(this.cross,function(o){return o.len我不知道dostuff和this.cross是什么,但假设您有一个属性为len的对象数组,并且希望筛选小于9的值 您可以使用无点函数样式,只使用

我正在尝试使用u.filter属性筛选数组。我想使用matchesProperty速记,但不想直接进行比较

这项工作: .每个(.filter(this.cross,['len',3]),dostuff)

但是如果我想过滤小于9的值,我需要使用一个函数:
.each(.filter)(this.cross,function(o){return o.len我不知道
dostuff
this.cross
是什么,但假设您有一个属性为
len
的对象数组,并且希望筛选小于9的值

您可以使用无点函数样式,只使用lodash,但它看起来比使用arrow函数更复杂。
matchesProperty
速记仅适用于相等比较,因此在这种情况下不能使用

请参见以下两个选项:

const arr=[
{len:2},//保持
{len:5},//保持
{len:9},
{len:22},
{len:8}//保持
]
//无点功能风格
const filtered=u0.filter(arr,0.flow(0.property('len'),0.partial(0.gt,9)))
//带箭头功能
常量filtered2=u0.filter(arr,o=>o.len<9)
console.log(已过滤)
console.log(filtered2)