gpt4 book ai didi

javascript - 当值为 true 时返回函数

转载 作者:行者123 更新时间:2023-12-03 01:25:05 24 4
gpt4 key购买 nike

我有一个场景,当 for 循环内的语句为 true 时,我需要返回一个值。根据下面的代码:当条件满足时我返回 false,但当循环中条件满足时我没有得到任何值。

function isFeatureAllowed(data){
_.each(user.restrictions.restrictedFeatures, function(restriction){
if(restriction.name.indexOf(data.toLowerCase()) !== -1){
return false;
}
})
}

console.log(isFeatureAllowed) should return true.
if(isFeatureAllowed){
//do something
}

如有任何帮助,我们将不胜感激。

最佳答案

假设restrictedFeatures是一个数组,您可以使用.every函数:

const isAllowed = feature =>
restrictedFeatures.every(r => !r.name.includes(feature.toLowerCase()))

关于javascript - 当值为 true 时返回函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51588731/

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