How to use includes() method In Javascript
The Javascript array.includes() method is used to know whether a particular element is present in the array or not and accordingly, it returns true or false i.e., if the element is present, then it returns true otherwise false.
Syntax:
array.includes(searchElement, start);
Example: This example shows the use of the array includes() method in Javascript.
const arr = ['Geeks','for','geeks','Javascript','HTML','CSS']
console.log(arr.includes('geeks'));
console.log(arr.includes('Javascript'));
console.log(arr.includes('CSS'));
console.log(arr.includes('React'));
Output
true true true false
Different ways to search an item in an array in JavaScript
Searching for an item in a JavaScript array involves determining whether a specific element is present within the array. This process is fundamental for tasks like data validation, filtering, and manipulation, enabling developers to locate and manage elements within arrays in their applications efficiently.
These are the following methods:
Table of Content
- Using find() method
- Using findIndex() method
- Using includes() method
- Using some() method
- Using indexOf() method
- Using filter() method
- Using every() method
Contact Us