gpt4 book ai didi

javascript - 如果数组中有假值则返回

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

我想要发生的是,如果任何值是假的,则仅返回错误,并且永远不要返回万岁。我正在使用lodash .

var jawn = [
{
"cheese" : true,
"with" : true,
"without" : true
},
{
"cheese" : true,
"with" : true,
"without" : true
},
{
"cheese" : true,
"with" : false,
"without" : true
},
{
"cheese" : true,
"with" : true,
"without" : true
}
];

_.forEach(jawn, function (item) {
if(item.with === false) {
console.log('error');
} else {
console.log('hooray');
}
});

最佳答案

由于您使用的是 undescore,请检查 Collections.every/all :

const msg = _(jawn).all(obj => obj.with) ? "hooray" : "error";
console.log(msg);

关于javascript - 如果数组中有假值则返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47822559/

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