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

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

    This also works fine, testing by type against undefined.

    if (currentData[index] === undefined){return}
    

    Test:

    const fruits = ["Banana", "Orange", "Apple", "Mango"];
    
    if (fruits["Raspberry"] === undefined){
      console.log("No Raspberry entry in fruits!")
    }

提交回复
热议问题