How to use the includes() Array method on a Bootcamp API

Victor
2 min readJan 16, 2022

One of the most used JavaScript Array methods I see get used the most is includes() method. The includes() method can be used in so many scenarios from testing code with jest, to showing or hiding content in the GUI, to disabling/enabling forms. In this short read, I’m going to break down what includes() is and how it’s used. The includes() method is attached to an Array of any type and its purpose is to scan an Array and return a boolean if a value in the Array matches the provided argument. This sort of method can be used to check if a user exists in an Array of type user, if a number exist in an Array of type numbers, and so much more. Before we do a deep-dive, let’s not confuse the some() method with the includes() method. The main difference between these two methods is that the some() method takes in an argument of type function while the includes() method take in an argument of string, number, etc.

Let’s take a look at how we use the includes() method on the Bootcamp API particularly the skills data set. As we can see it’s a basic Array of type strings with values equating to that seen in any Software Developer’s resume.

An array of skills gained from attending a Bootcamp

Let's see how the includes() method works with the Array and what argument gets passed in.

includes method attached to Array of strings

Lastly, now that we’ve been able to pass an argument let’s see if it exist or does not exist based on the results variable.

includes method attached to Array of strings returning boolean.

And there we have it, the includes() method checks if a value exists in an Array and if it does it returns true if not it returns false. Here’s a great video explaining it further from the owner of kindofastartup.com check it out.

--

--