The JavaScript Array includes() Method returns true if an array contains a specified value. The includes() method is case-sensitive.
Syntax:
array.includes(searchElement, start);
Parameters:
- searchElement: This parameter holds the element that will be searched.
- start: This parameter is optional and it holds the starting point of the array, where to begin the search the default value is 0.
Return Value:
It returns a Boolean value i.e., either True or False.
Example 1: In this example, we will see if a value is included in an array or not using the Array includes() method.
javascript
let name = ['gfg', 'cse', 'geeks', 'portal'];
a = name.includes('gfg')
console.log(a);
|
Example 2: In this example, the method will search for element 2 in that array.
javascript
let A = [1, 2, 3, 4, 5];
a = A.includes(2)
console.log(a);
|
Example 3: In this example, the method will search for the element ‘cat’ in that array and returns false as ‘cat’ is not present in the array.
javascript
let name = ['gfg', 'cse', 'geeks', 'portal'];
a = name.includes('cat')
console.log(a);
|
We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete referencearticle.
Supported Browsers:
- Google Chrome 47.0
- Microsoft Edge 14.0
- Mozilla Firefox 43.0
- Safari 9.0
- Opera 34.0
We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.
Learn to code easily with our course
Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated :
10 Jan, 2024
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...