Skip to content

Instantly share code, notes, and snippets.

@sabrinaluo
Last active August 29, 2015 14:11
Show Gist options
  • Save sabrinaluo/440812106396219f1523 to your computer and use it in GitHub Desktop.
Save sabrinaluo/440812106396219f1523 to your computer and use it in GitHub Desktop.
find element index in array; check whether element is in array
var array = ["lily", "tom", "lucy"];
var ele1 = "lily";
var ele2 = "lucy";
var ele3 = "jack";
array.indexOf(ele1); // return 0
array.indexOf(ele2); // return 2
array.indexOf(ele3); //return -1; NOTE: element is not in the array if return -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment