我有一个如下数组var goal = [ { "category" : "education", "title" : "Charlie University", "description" : "Lorem ipsum dolor sit amet", "date" : "01/03/2020", "value" : 50000, "achievability" : 3, "experimental_achievability": 3, "designation": "{"id":1, "jobCode":1003}", "suggested": false, "accounts": [], "articles": [], "related_goals": [], "id":"1" }, { "category" : "education", "title" : "Charlie University", "description" : "Lorem ipsum dolor sit amet", "date" : "01/03/2020", "value" : 50000, "achievability" : 3, "experimental_achievability": 3, "designation": "{"id":2, "jobCode":1004}", "suggested": false, "accounts": [], "articles": [], "related_goals": [], "id":"2" }, ]如何"designation": "{"id":2, "jobCode":1004}",使用下划线 JS 从目标数组中获取具有属性的对象。我可以为此使用 _.findWhere 吗?
1 回答
汪汪一只猫
TA贡献1898条经验 获得超8个赞
你不需要下划线,你可以使用 Array.find
goal.find(function(item) {
return item.id === 2 && item.jobCode === 1004
})
es2015 示例:
goal.find(item => item.id === 2 && item.jobCode === 1004)
添加回答
举报
0/150
提交
取消