作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在使用 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/
我是一名优秀的程序员,十分优秀!