+ 2

Is there anyway to display items in an array without using document.write()

From what I have learnt so far, I know that document.write() is for testing purposes. So I was trying different methods but they were not working. Then I decided to consult my Sololearn friends if you can help??

7th Apr 2021, 2:44 PM
Zico
Zico - avatar
3 Respuestas
+ 1
You can select the element using document.querySelector("#example"); And then use innerHTML or innerText to set the content. The difference between the two is that innerHTML sets the HTML markup and innerText only sets the text. For example: Assume in the HTML there is an item with an id of heroes var heroes = document.querySelector("#heroes"); let namesOfHeroes = ["iron man", "spiderman", " superman"] for(let i =0; i < namesOfHeroes.length; i++){ heroes.innerHTML += namesOfHeroes[i] + "<br/>" }
7th Apr 2021, 3:14 PM
Mwikisa Kapesa Lufungulo
Mwikisa Kapesa Lufungulo - avatar
+ 2
console.log(); and alert(); are the another method to display arrays, booleans and so on. Happy Coding!
7th Apr 2021, 3:04 PM
Matias
Matias - avatar
0
Ryan Zico (Challenge Me) What methods did you try? I'm curious to know what didn't work and why as I think it would be good to learn/see. If this is for debugging/development purposes, I can recommend console.log() and console.dir(). You may need to JSON.stringify() your array if it contains objects.
7th Apr 2021, 3:32 PM
CamelBeatsSnake
CamelBeatsSnake - avatar