From the course: JavaScript: Arrays

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Does the array Include an element?

Does the array Include an element? - JavaScript Tutorial

From the course: JavaScript: Arrays

Does the array Include an element?

- [Instructor] The array method includes checks an array for a specific value. It will then return a Boolean, true or false, to indicate whether or not a value was found within a specific array. The syntax is fairly simple. You pass the array method the value you want to search for in the array. Keep in mind that this value is case sensitive. Additionally, there's an optional parameter called fromIndex, which indicates from what index position you want the method to start searching. For the purposes of this lesson, we're going to focus simply on passing a value to search as this will be the most common implementation of the array method. Let's look at a quick example to see includes an action. We have an array of scores and we want to see if it includes a perfect score of 10. All we have to do is pass the score we're looking for, 10, and the array method will return True, indicating that 10 is included in the array. Now…

Contents