我正在尝试遍历一个数组,它检查每个元素是否为空。如果数组中的所有元素都是空的,并且 output[library] 是空的,那么我不想打印任何东西。如果数组中包含单个元素,我想打印该元素。到目前为止我已经尝试过了,但是程序有一个错误,它没有将参数输出传递给导致错误的 arrayIsEmpty,我也不知道如何遍历每个元素,例如第一次运行可能有一个项目数组,我想打印它,然后我希望它从最后一个位置继续,所以检查位置二是否为空等(我希望我试图通过的东西是有意义的)。
for (var library in output)
{
if (opt.options.showEmpty != true)
{
console.log("It has made it to here 1 ");
var check = arrayIsEmpty(output);
console.log("It has made it to here 2 ");
if ( check == false && output[library] == "" )
{
console.log("It has made it to here 3 ");
continue;
}
else
{
console.log("It has made it to here 4 ");
console.log(library+ ",[" + output[library]+"]");
}
}
//console.log(library+ ",[" + output[library]+"]");
}
}
});
}
function arrayIsEmpty(attributes)
{
console.log("IT HAS MADE IT INTO ARRAYISEMPTY");
for(var i = 0; i < attributes.length; i++)
{
console.log("IT IS NOW IN THE FOR LOOP");
if (attributes[i] == "")
{
console.log("IT SHOULD BE FALSE HERE");
return false;
}
else
{
console.log("IT SHOULD BE TRUE HERE");
return true;
}`enter code here`
}
我输入了console.log语句,它正在读取“它已经到达这里1”然后它已经进入arrayISEmpty”然后“它已经到达这里2”然后“它已经到达这里4”所以它不返回 true 或 false