I have the following array:
results = ["Dog","Cat","Fish","Parrot"];
I join it using the .join method like so:
var finalResult=results.join("\n");
I have a div:
Validation Result:<div id="result"></div>
I then try to render it inside a div like so:
this.shadowRoot.getElementById('result').textContent = finalResult;
This just ends up being rendered with a space between each word:
Dog Cat Fish Parrot
I want it to paste each string on a new line like so:
Dog
Cat
Fish
Parrot
I can't seem to be able to achieve this. Any suggestions on how I can achieve this?
Using <br> instead of \n will solve your issue.
Maybe you can try as the following:
const results = ["Dog","Cat","Fish","Parrot"];
const div = document.getElementById('elements');
div.innerHTML = results.join('<br>');
<div id="elements"></div>
Suggested articles to read:
<br>: The Line Break elementI hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With