eug
eug

Reputation: 23

How can I add non-breaking space to a string in JavaScript?

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

Answers (1)

Bergi
Bergi

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

Related Questions