The includes()
method searches
for an element in the array.
If the element is present
in the array,
it returns true
.
If the element is not present
in the array,
includes()
returns false
.
In the above example, we haven't used indexOf()
method
instead of includes()
, because of the purpose for which
each of these methods were created in the first place.
indexOf()
is used when
we not only have to check
if an element is found in an array,
but also know the index of the element
in that array.
includes()
is used when we only need
to check for the presence of an element.