Created
July 27, 2016 06:14
-
-
Save omurphy27/c64ba822bb52a0d6b9d12ed5916e4620 to your computer and use it in GitHub Desktop.
JS - Javascript - Finding a match in a JS array with indexOf
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
// where this.conditionsLetters is | |
// ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"] | |
if ( this.conditionsLetters.indexOf( $letter ) > -1 ) { // check if match found | |
this.selectedConditionsLetter = $letter; | |
} | |
// no match returns -1, | |
// whereas a match returns the zero base position in the array which is always greater than -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment