Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

loop array in javascript

function in_array(needle, haystack){
    var found = 0;
    for (var i=0, len=haystack.length;i<len;i++) {
        if (haystack[i] == needle) return i;
            found++;
    }
    return -1;
}
if(in_array("118",array)!= -1){
//is in array
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #loop #array #javascript
ADD COMMENT
Topic
Name
3+8 =