eve eve - 1 year ago 104
Javascript Question

Replace multiple whitespaces with single whitespace in JavaScript string

I have strings with extra whitespaces, each time there's more than only one whitespace I'd like it be only one.

I tried searching google, but nothing worked for me.


Answer Source

Something like this:

s.replace(/\s+/g, ' ');