I am trying to get a string like the following one:
[==== ]
For that purpose I am using this code:
This is an issue of Chrome's developer tools. Empty spaces can be repeated, but they are displayed as one character, which is wrong:
You can check the result like this:
(' ' + ' ').length
// => 2
Here is an example from Node.js REPL:
In conclusion, your code does work, but Google Chrome's console doesnt display the result correctly.
If you're talking about the displaying in HTML elements that don't have monospace fonts, use @Jamiec's solution, using non-breaking spaces:
'[' + '='.repeat (4) + ' '.repeat(4) + ']'
As @James Thorpe this was a bug in Chrome which got fixed. Probably we will get the fix when updating the browser version.
Browsers collapse multiple whitespace, in order to force it not to you can use non-breaking spaces.
Therefore, in your case you can use
' '.repeat(4)
(Its arguable that a debug console shouldn't collapse the whitespace, but in your case it seems it does)