trim in javascript

how can i do that?
i need just like in VB : trim(str)


e.
LVL 1
eladrAsked:
Who is Participating?
 
knightEknightConnect With a Mentor Commented:
the most convenient way is to use the function as noted above, but you can simply do this:

   var str = "  this is a test   ";

   str = str.replace(/^\s*|\s*$/g,"");
0
 
knightEknightCommented:
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
0
 
knightEknightCommented:

var str = "  this is a test   ";

str = trim(str);
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
waqar2004Commented:
KnightEknight

good work.
0
 
rkarthik29Commented:
var str = "  this is a test   ";

str = Trim(str);
0
 
knightEknightCommented:
the function is case sensitive

str = trim(str);


:)
0
 
stevenlevithanCommented:
This post compares a variety of ways to <a href="http://blog.stevenlevithan.com/archives/faster-trim-javascript">trim in JavaScript</a>.
0
All Courses

From novice to tech pro — start learning today.