Reputation: 23
I want to display an array of strings in HTML with a random number of white spaces in front of the string in the array. How would I go about doing this in JavaScript?
I first did a loop of the array and tried adding " " to each string in the array, but the white spaces don't show up. I also tried adding , but it doesn't get interpreted in JavaScript.
Upvotes: 2
Views: 2266
Reputation: 664538
Adding non-breaking spaces should work.
However, the crucial part of displaying white space in an HTML document is to set the white-space
CSS property of the relevant elements to pre
or pre-wrap
.
Upvotes: 1