Map Data Structure in JavaScript
Level 4288 keystrokes
Map provides a key-value data structure with methods like set, get, has, delete and size property.
JavaScript code
// Create a new Map for user roles1const userRoles = new Map();// set() adds a key-value pair: user name → role2userRoles.set("alice", "admin");3userRoles.set("bob", "editor");4userRoles.set("charlie", "viewer");// get() returns the value for a key: admin5console.log(userRoles.get("alice"));// has() checks whether a key exists: true6console.log(userRoles.has("bob"));// size is the number of entries: 37console.log(userRoles.size);// delete() removes the entry for a key8userRoles.delete("charlie");// Size is now 29console.log(userRoles.size);Output
admin true 3 2
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
"× 18.× 12(× 11)× 11;× 9,× 3=× 1