Last active
August 29, 2015 14:11
-
-
Save sabrinaluo/440812106396219f1523 to your computer and use it in GitHub Desktop.
find element index in array; check whether element is in array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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