In this article, I am going to describe 4 methods

- Using The indexOf() method
- Check if array includes a value in Javascript
- Check for NaN
- Check for Undefined

Using The indexOf() method

Using `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.

Read more …




Playing with strings in Javascript is a bit tricky. In this article, I am going to describe how to remove space from any string in Javascript.

Even though Javascript provides many inbuilt string functions, we must always aim for using the optimal one to solve any challenge.

Because JavaScript uses the main UI thread and any redundancy can cause a lag in the UI.

Space can be present at any position in a string and, a single solution will not work in every situation.

In this article, I have discussed two ways to:

  1. Remove all extra spacing between words.
  2. Trim the extra space from the beginning or end of a string.