String trim() Method - Javascript String

Javascript examples for String:trim

Description

The trim() method removes whitespace from both sides of a string.

The trim() method does not change the original string.

Parameters

None.

Return Value:

A String, representing the string with removed whitespace from both ends

The following code shows how to Remove whitespace from both sides of a string:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<script>

function myFunction() {/*from  w  w w  .  ja v a2 s .  co  m*/
    var str = "        Hello World!        ".trim();
    console.log(str);
}
</script>

</body>
</html>

Related Tutorials