js method string remove extra spaces
snippet in javascript

remove spaces in a string js

user1282

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

js method string remove extra spaces

user7411

const sentence = '    My string with a    lot   of Whitespace.  '.replace(/\s+/g, ' ').trim()

// 'My string with a lot of Whitespace.'

javascript remove all spaces from string

user3328

str = str.replace(/\s/g, '');