我有一个Map = {'key-string',value as object}和一个List []和一个字符串'TEST',
在这里,我需要根据地图中的String和Array进行两项检查,
例如,
if(Map.has('TEST')) {
Need to do some logic
} else {
if(Array.includes('TEST') {
Need to do some manipulation
} else {
Need to do some manipulation
}
}
我已经尝试过如上所述的方法来满足自己的需求。这是最佳做法吗?给我建议。
答案 0 :(得分:1)
if(Map.has('TEST')) {
Need to do some logic
} else if(Array.includes('TEST')) {
Need to do some manipulation
} else {
Need to do some manipulation
}
使用Else If
编辑1:既然您说过您需要检查2件事,也许这更适合,但我不确定您的问题是否很模糊。
// || = OR
if(Map.has('TEST') || Array.includes('TEST')) {
Need to do some logic
} else {
Need to do some manipulation
}