我得到了以下对象数组
[
{
"name": "Jack Daniel",
"job": "Software Developer",
"age" : "40M"
},
{
"name": "Sofia Daniel",
"job": "Web Developer",
"age" : "35F"
},
{
"name": "John Smith",
"job": "Marketing",
"age" : "32M"
},
{
"name": "Clara Johnson",
"job": "Designer",
"age" : "35F"
}
]
现在使用lodash我可以过滤年龄或我喜欢的任何属性,但我怎样才能实现以下目标。
我觉得这很简单。
答案 0 :(得分:0)
您可以在纯JavaScript中使用filter()
indexOf()
。
var data = [{"name":"Jack Daniel","job":"Software Developer","age":"40M"},{"name":"Sofia Daniel","job":"Web Developer","age":"35F"},{"name":"John Smith","job":"Marketing","age":"32M"},{"name":"Clara Johnson","job":"Designer","age":"35F"}]
var result = data.filter(function(e) {
return e.age.indexOf(35) != -1 && e.name.toLowerCase().indexOf('daniel') != -1;
})
console.log(result);