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

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

    Simple way to check item exist or not

    Array.prototype.contains = function(obj) {
        var i = this.length;
        while (i--)
           if (this[i] == obj)
           return true;
        return false;
    }
    
    var myArray= ["Banana", "Orange", "Apple", "Mango"];
    
    myArray.contains("Apple")
    

提交回复
热议问题