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 */ }
4 Antworten
+ 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.
+ 1
All keys and values are output when I run it. So, not sure what you're asking.
+ 1
using map as a variable name is bad practice because map is already a key word.
0
Check using innerHTML