我正在使用lodash.js过滤我的json值。我需要像Lodash中的Mysqls " in“函数一样的东西。
json value:
[
{id:1,customer:5},{id:2,customer:6},{id:3,customer:6},{id:2,customer:7}
]我想在lodash中选择"customer in(6,7)"。我该怎么做呢?
发布于 2020-05-20 23:41:41
您可以在集合上使用lodashes filter函数。
const input = '[{"id":1,"customer":5},{"id":2,"customer":6},{"id":3,"customer":6},{"id":2,"customer":7}]';
const mysqlIn = (json, array) => {
const data = JSON.parse(json);
let ans = _.filter(data, function(x) {
return array.includes(x.customer);
});
return ans;
}
console.log(mysqlIn(input, [6,7]));<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
https://stackoverflow.com/questions/61916035
复制相似问题