includes method
The includes method checks for
the presence of an element in an array. The
parameter takes the value to search. If
there is such an element in the array,
then the method returns true,
and if not, then false.
Syntax
javascriptarray.includes(element);
Example
Let's check if an element exists in an array:
javascriptlet arr = [1, 2, 3, 4, 5];
let res = arr.includes(3);
console.log(res);
The code execution result:
javascripttrue
Example
Let now the element being checked is not in an array:
javascriptlet arr = [1, 2, 3, 4, 5];
let res = arr.includes(6);
console.log(res);
The code execution result:
javascriptfalse