- Using The indexOf() method
- Check for NaN
- Check for Undefined
indexOf(), we can determine if an element is present in an array or not. Similar to the
includes() method the
indexOf() method also works on arrays and, it takes one argument.
See the code below.
var students = ["john", "jane", "jim"]; console.log( students.indexOf("jane") > -1 ); // true
Even though the
indexOf() method supports both old and new browsers, it has few drawbacks.