JavaScript Glossary - Lesson #9

JavaScript Array .includes() Method

This method checks if an array contains a given element. The return value for this method is a Boolean. true if the element exists in the array and false if otherwise.

[10, 20, 30, 40].includes(50)
// False
//  Create an array of names
const classNames = ['amazon', 'facebook', 'google', 'scotch']

// Verify inclusion in classNames
let partOfClass = classNames.includes('microsoft')

// output: false


  • Takes a value as an argument
  • Checks the array if the value exists within the array
  • Returns true or false.
  • If no argument is provided, it returns false.
array.includes(searchValue, startIndex)

searchValue This is the value to search the array for.

startIndex (optional) This the position in the array at which the search begins.

The method will return an the Boolean true if the array contains the searchValue and false if it doesn’t. If no arguments are provided, false is returned by the method.

const names = ['Johnny', 'Pete', 'Sammy']
const myName = 'Pete';

const hasMyName = names.includes(myName);
// output: true

The includes method is commonly used to check if an array has a certain value in it.

Search Days of the Week

// Weekdays
const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];

// Random month
const month = 'May';

// Verify inclusion in array
const isDay = days.includes(month);

// output: false

Want to improve your coding and design skills?

I'm continually researching the best practices and tools for coding.
Join 50,000+ developers looking to make cool stuff.

We value your privacy. 1-click unsubscribe.

Chris Sev

Chris Sev

Chris Sev is the co-founder of Better Dev. Coding better every day. Previously he created which was acquired.


What did you think of the article? Let us know!
(these comments are powered by GitHub issues and use 0 trackers)