Replace multiple whitespaces with single whitespace in JavaScript string

Something like this:

var s = "  a  b     c  ";

console.log(
  s.replace(/\s+/g, ' ')
)

Leave a Comment