Create a function to remove all spaces from a given string js code example
Example 1: 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.'
Example 2: javascript remove all spaces from string
str = str.replace(/\s/g, '');