includes
ExamplesΒΆ
The general syntax for this method is:
arrayName.includes(item)
This method checks if an array contains the item specified in the
parentheses ()
, and returns true
or false
.
Example
1 2 3 4 5 6 | let charles = [1, 7, 5, 9, 5];
let otherArr = ['hello', 'world!'];
console.log(charles.includes(5));
console.log(otherArr.includes('hi'));
|
Output
true
false