gpt4 book ai didi

javascript - 使用 lodash 根据对象的值过滤对象

转载 作者:行者123 更新时间:2023-11-30 12:05:05 28 4
gpt4 key购买 nike

我如何使用 lodash 获得以下输出?

input = {
'property1' : true,
'property2' : false,
'property3' : false
}
// only pick those properties that have a false value
output = ['property2', 'property3'];

我目前有以下内容:

var output = [];
_.forEach(input, (value, key) => {
if (value === false) {
output.push(key);
}
});

最佳答案

你可以做的普通 JS:

var output = Object.keys(input).filter(function(k) { return input[k] === false })

关于javascript - 使用 lodash 根据对象的值过滤对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35466556/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com