Replace multiple whitespaces with single whitespace in JavaScript string October 15, 2022 by Tarik Something like this: var s = " a b c "; console.log( s.replace(/\s+/g, ' ') )