Trim function in javascript

what is the function to trim a string,
which we can trim in asp
gopigoudAsked:
Who is Participating?
 
wailqillCommented:
You can paste this into your code:

String.prototype.trim=function() {
      return this.rtrim().ltrim()
}
String.prototype.ltrim=function() {
      return this.replace(/^\s*/,'')
}
String.prototype.rtrim=function() {
      return this.replace(/\s*$/,'')
}

then you can use this syntax with every string-object U have on your page:

stringname.trim()
or
stringname.ltrim() // left trim
or
stringname.rtrim() // right trim

or even "  dsaf as ".trim()
0
 
CJ_SCommented:
ther eis no Trim-a-like function in javascript. You should make it yourself.
0
 
qader99Commented:
the above code helps

Thanks a lot..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.