Loading...
JavaScript

Trim All Whitespaces From String in JavaScript

JavaScript’s inbuilt method trim() removes whitespace from both ends of a string.

The Syntax: str.trim()

The method returns new string representing the str stripped of whitespace from both ends.

var message = " Hello World  ";
console.log(message.trim());
// Output: "Hello World"

Try yourself

Share this article with your friends
Leave a Reply

Your email address will not be published. Required fields are marked *