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

前端 未结 18 1703
粉色の甜心
粉色の甜心 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:40

    Consider the array a:

    var a ={'name1':1, 'name2':2}
    

    If you want to check if 'name1' exists in a, simply test it with in:

    if('name1' in a){
    console.log('name1 exists in a')
    }else
    console.log('name1 is not in a')
    

提交回复
热议问题