by @codeexamples

How to trim a string in JavaScript ?

Home » javascript » How to trim a string in JavaScript ?

JavaScript has a built-in trim() method by using that we remove the whitespaces from both ends of a string.

Here is an example:

var name = "   olive   ";

console.log(name.trim()); //  "olive"