javascript, jQuery - check if value exists in array


This question already has an answer here:


var codes = ["US-AL", "US-AZ", ... ];

if($.inArray(code, codes) > -1){
    //do something    

UPDATE: Incorporating @Deestan's suggestion, this could be re-written as..

function isValidCode(code){
    return ($.inArray(code, codes) > -1);


array.indexOf(searchElement[, fromIndex])

Need Your Help

Is there an HTML CSS testing bin similar to jsbin

html css testing

Is there a page similar to JSbin where I can test HTML and CSS + provide "fiddlable" examples to you?

Skip certain tables with mysqldump

sql mysql database mysqldump

Is there a way to restrict certain tables from the mysqldump command?