How to remove the whitespace from both sides of the string by using JavaScript?

In this article we will discuss to remove the whitespace from both sides of the string by using JavaScript. We should use trim() method for removing whitespace.

For example:

<script type="text/javascript">

    var firststring = "infinet ";

    var secondstring = "soft ";

    var result = firststring.trim() + secondstring.trim();

    alert(result);
  </script>


remove whitespace using trim()