我在 NodeJS 应用中使用lodash。我想使用_.find
。
但我必须等待_.find
完成,以便我可以使用找到的信息,否则当我想使用它时它将是undefined
。
var items = [
{ id: 001
// Super Object
// +150 properties each
},
{ id: 002 } // up to 200
];
var foundItem = _.find ( items , { id: 002 });
console.log(foundItem);
// => logs Undefined
我该怎么办?我需要等待lodash _.find
完成才能打印找到的项目。
答案 0 :(得分:4)
看到你已经将你的ID写成001
我猜他们是字符串而不是数字,所以也许引用你的价值就可以了:
var foundItem = _.find ( items , { id: '002' });