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

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

    If you use underscore.js then these type of null and undefined check are hidden by the library.

    So your code will look like this -

    var currentData = new Array();
    
    if (_.isEmpty(currentData)) return false;
    
    Ti.API.info("is exists  " + currentData[index]);
    
    return true;
    

    It looks much more readable now.

提交回复
热议问题