Vanarajan Vanarajan - 1 month ago 10
jQuery Question

How to trim the string using node.js?

I am trying to trim the string. I google it for trim.

The tips i am getting.


  1. name.trim(); -- Not recognized trim() function

  2. npm install --save string

    var S = require('string');
    S('hello ').trim().s; -- this also same issue



Can you any one assist me what is the problem of the above method or anything i have missed it?

Answer

You don't need jquery for this...

var str = "       Hello World!        ";
var trimmedStr = str.trim();
console.log(trimmedStr);

This will output the following in the console:

"Hello World!"

Comments