let teachers = new Map(); teachers.set("grade 1", "Mrs Johnson"); teachers.set("grade 2", "Mr Bennett"); for (let [key, value] of teachers) { console.log(key + ' = ' + value); } // grade 1 = Mrs Johnson // grade 2 = Mr Bennett for (let key of teachers.keys()) { console.log(key); } // grade 1 // grade 2 for (let value of teachers.values()) { console.log(value); } // Mrs Johnson // Mr Bennett for (let [key, value] of teachers.entries()) { console.log(`The ${key} teacher is ${value}.`); } // grade 1 = Mrs Johnson // grade 2 = Mr Bennett
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter