How to add spaces in a JavaScript string?

To add spaces in a JavaScript string, do this: string.split('').join(' ').

Here's how you do it:

const string = 'Hello World!';

const withSpaces = string.split('').join(' ');

console.log(withSpaces); // H e l l o   W o r l d !