Home > OS >  How to attach an html to a div, with javascript expression inside?
How to attach an html to a div, with javascript expression inside?

Time:10-04

I am trying to use innerHtml property to attach an html with javascript expression to a div. But I get to see output as only [object]. How to achieve it? The code is below...

document.getElementById("userlist").innerHTML = <ul>{userInfo.map((name, id) => <li><Link to="userpage?id="{...id}>{name}</Link></li>)}</ul>

Here UserInfo is an array of objects. Is there any other way to do the thing? how?

CodePudding user response:

document.getElementById("userlist").innerHTML =

    ${userInfo.map((name, id) => "
  • <Link to="userpage?id="{...id}>{name}
  • )}
`

CodePudding user response:

try the String() <Link to="userpage?id="{...id}>{String(name)}</Link>

  • Related