Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created July 6, 2017 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save prof3ssorSt3v3/2353cfafcb2ff25e9e40275ba79d01b2 to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/2353cfafcb2ff25e9e40275ba79d01b2 to your computer and use it in GitHub Desktop.
//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