Output JS Array in HTML

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <ul id="demo"></ul> <script> var persons = [ {firstname : "Malcom", lastname: "Reynolds"}, {firstname : "Kaylee", lastname: "Frye"}, {firstname : "Jayne", lastname: "Cobb"} ]; for (i=0; i<persons.length; i++){ nameList = "<li>" + persons[i].firstname + " " + persons[i].lastname + "</li>"; document.getElementById("demo").innerHTML+=nameList; } </script> </body> </html>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.