+ 1
No Space between array items
I want display array items in space between but spaces does not apply why? My code: https://code.sololearn.com/WlaCOvT7M45R
4 Answers
+ 2
Try assigning to .innerHTML or .textContent rather than to .innerText. Looks like whitespace is collapsed when assigning to .innerText
* Tested on SoloLearn app only.
+ 2
with innerText No space
with innerHtml and textcontent only one character space
+ 2
Then use .innerHTML with replicated HTML entity in place of blank spaces.
document.getElementById("p1").innerHTML += fruits[key] + " ".repeat(20); // 20 non-breaking-space