+ 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

21st Jul 2022, 4:20 AM
Hadi
Hadi - avatar
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.
21st Jul 2022, 4:38 AM
Ipang
+ 2
with innerText No space with innerHtml and textcontent only one character space
21st Jul 2022, 4:44 AM
Hadi
Hadi - avatar
+ 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
21st Jul 2022, 5:05 AM
Ipang