How to check if array element exists or not in javascript?

前端 未结 18 1726
粉色の甜心
粉色の甜心 2020-12-07 10:05

I am working with Titanium, my code looks like this:

var currentData = new Array();

if(currentData[index]!==\"\"||currentData[index]!==null||currentData[ind         


        
18条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 10:27

    Use typeof arrayName[index] === 'undefined'

    i.e.

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

提交回复
热议问题