2

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.

1
  • What you do seems to be correct. A simple code sample might help get clarity on the issue you are facing. I am adding ' ' to a string with no javascript problems. jsfiddle.net/d2btyr5k Commented Jan 29, 2016 at 1:43

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.