gpt4 book ai didi

javascript - 如何在javascript中检查数组索引是否存在?

转载 作者:IT老高 更新时间:2023-10-28 13:17:07 26 4
gpt4 key购买 nike

我正在使用 Titanium,我的代码如下所示:

var currentData = new Array();
if(currentData[index]!==""||currentData[index]!==null||currentData[index]!=='null')
{
Ti.API.info("is exists " + currentData[index]);
return true;
}
else
{
return false;
}

我正在向 currentData 数组传递一个索引。使用上述代码,我仍然无法检测到不存在的索引。

最佳答案

使用 typeof arrayName[index] === 'undefined'

if(typeof arrayName[index] === 'undefined') {
// does not exist
}
else {
// does exist
}

关于javascript - 如何在javascript中检查数组索引是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13107855/

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