0

Js map using innerHTML Why only last key value print

Js map using innerHTML Why only last key value print https://code.sololearn.com/WBgtHWJIynz3 let map = new Map(); map.set('fname','Abhi').set('lname','ji').set('mobile',999999999); for (let iterator of map.entries()) { document.getElementById("demo").innerHTML=iterator[0] + " : " + iterator[1] ; //mobile : 999999999 console.log(iterator[0] + " : " + iterator[1]); /*fname : Abhi lname : ji mobile : 999999999 */ }

15th Nov 2020, 2:22 PM
ASP
ASP - avatar
4 odpowiedzi
+ 3
Well of course it's only going to output the last change made. You're not appending to it, you're replacing it each time.
15th Nov 2020, 3:01 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
All keys and values are output when I run it. So, not sure what you're asking.
15th Nov 2020, 2:52 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
using map as a variable name is bad practice because map is already a key word.
16th Nov 2020, 1:12 AM
Logomonic Learning
Logomonic Learning - avatar
0
Check using innerHTML
15th Nov 2020, 2:57 PM
ASP
ASP - avatar