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
1let charles = [1, 7, 5, 9, 5];
2let otherArr = ['hello', 'world!'];
3
4console.log(charles.includes(5));
5
6console.log(otherArr.includes('hi'));
Output
true
false