Created
July 6, 2017 18:11
-
-
Save prof3ssorSt3v3/2353cfafcb2ff25e9e40275ba79d01b2 to your computer and use it in GitHub Desktop.
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
//Array includes() method | |
//check to see if something is inside an array | |
//method returns a Boolean answer | |
let dwarves = ['Grumpy', 'Sneezy', 'Happy', 'Bashful', 'Doc', 'Dopey', 'Sleepy']; | |
let name1 = 'Peter Dinklage'; | |
let name2 = 'Kenny Baker'; | |
let name3 = 'Happy'; | |
let hasPeter = dwarves.includes(name1); | |
let hasKenny = dwarves.includes(name2); | |
let hasHappy = dwarves.includes(name3); | |
let hasHappy3 = dwarves.includes(name3, 3); | |
console.log("contains Peter", hasPeter); | |
console.log("contains Kenny", hasKenny); | |
console.log("contains Happy", hasHappy); | |
console.log("contains Happy after index 3", hasHappy3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment