Skip to content

Instantly share code, notes, and snippets.

@akoumjian
Created October 31, 2011 19:28
Show Gist options
  • Save akoumjian/1328598 to your computer and use it in GitHub Desktop.
Save akoumjian/1328598 to your computer and use it in GitHub Desktop.
indexof example
var myCars=["Saab","Volvo","BMW"]; // literal array
if (myCars.indexOf("Saab")) {
console.log("It's in the list!")
}
else {
console.log("Nope, not there.")
}
// using jQuery is better
if (jQuery.inArray($('#input_id').val(), myCars)) {
// do stuff
}
else {
// do other stuff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment