[javascript] 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.

Anyone? I tried searching google, but nothing worked for me.


This question is related to javascript string trim

The answer is

Something like this:

var s = "  a  b     c  ";_x000D_
  s.replace(/\s+/g, ' ')_x000D_

Similar questions with javascript tag:

Similar questions with string tag:

Similar questions with trim tag: