I have:
var a = ['bla bla bla', 'bla bla', 'bla']
and would like when I display this HTML, after every , to be new line (<br />), but I do not know how to do this. I tried this:
var a = ['bla bla bla', 'bla, bla', 'bla']
{a.map(b => {
return b <br /> //but this getting error .... whitout <br /> don't get error but doesn't have new line
})
}
I do not know how long array a will be, because of this I did not do:
{a[0] }
<br />
{a[1]}
<br />
CodePudding user response:
a.map(b => {
return <>{b}<br /></>
});
CodePudding user response:
You don't want to use map here. Try join instead.
const fullString = a.join('<br/>')
Though, it's really unclear how you are outputting this.
CodePudding user response:
Instead of adding "<br />", I recommend to use built in JSON functions:
var a = ['bla bla bla', 'bla, bla', 'bla'];
a = JSON.stringify(a, null, 4)
document.getElementById("output").innerText = a
<div id="output"></div>
