我正在使用 sonarqube 来检查代码的质量,sonarqube 发现数组始终大于或等于 0。
$.each(ssntxtArrayText, function (index, value) {
if (value.length >= 0) {
$('#resultValidation').css({
'display': 'none',
});
return false;
}
else {
$("#resultValidation").removeAttr("style");
}
});
只需将 if (value.length >= 0)
更改为 if (value.length > 0)
即可解决问题,或者会影响其余内容发生什么事了?
最佳答案
sonarqube has found arrays will always [have length] greater than or equal to 0.
独立于sonarqube,这在JS中总是正确的。即,您的 if 条件是不必要的,您的代码相当于
$.each(ssntxtArrayText, function (index, value) {
$('#resultValidation').css({
'display': 'none',
});
return false;
});
如果这是故意的,请继续删除 if 语句。如果这不是故意的,那么修复将取决于预期的行为。
关于javascript - 集合大小和数组长度 - sonarqube,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55797131/