DEV Community 👩‍💻👨‍💻

Shyam Mohan Kunwar
Shyam Mohan Kunwar

Posted on

Trim in JavaScript

trim method in javascript

If you want to remove the extra space in your string data type, here is a simple way to do it in JavaScript.

Programming in JavaScript is easy once you know the language's in and out.

JavaScript offer String.trim() method.

trim() method removes the removes all whitespace from both ends of a string,
including tabs, spaces, no-break spaces, and line terminator characters.

Example of Trim() method in JS:

const extraSpaceString = ' Hi This is shyam from cyberncode.com, Please visit cyberncode.com for more awesome blogs. ';
const trimString = extraSpaceString.trim();
console.log(trimString);

Output:
trim in javascript output

Also Read: Make your own notepad app with different features in a minute using pure HTML

Top comments (0)

Your PRs make a difference 😍

We've got a great set of issues to modernize our JS management on the platform. Can you pitch in?