how to remove any extra spaces at the end of a string js code example
Example 1: remove spaces in a string js
str.replace(/\s+/g, '')
Example 2: js method string remove extra spaces
const sentence = ' My string with a lot of Whitespace. '.replace(/\s+/g, ' ').trim()
// 'My string with a lot of Whitespace.'