Trim in JavaScript

Source code :

 var str = "       Hello World!       ";
    alert(str.trim());

Output :

Hello World!

Algorithm :

  1. Initialize a variable with string values contains white space
  2. Use the keyword trim to remove the white space
  3. Print the result

Output :


                

Comments :