节点阵列过滤不起作用

时间:2016-11-16 10:12:06

标签: javascript node.js

我正在尝试过滤一个数组,因为我过去有一百万次,但它不起作用。

locations = city.locations.filter(
   (l) => {
     console.log(l._id);
     console.log(req.query.locationId);
     console.log(l._id === req.query.location);
     return l._id === req.query.location;
   }
)

控制台输出:

l1dr2jmg42lb2sgiudi
l1dr2jmg42lb2sgiudi
false

前两个console.log打印相同的字符串,但第三个打印错误??!?

我检查city.locationsArrayl._idreq.query.locationId都是string

1 个答案:

答案 0 :(得分:3)

console.log(l._id === req.query.location);

您不是指req.query.locationId而是指req.query.location。缺少Id