To create an associative array in JavaScript literal notation, we can create a map.
For instance, we write
const arr = new Map([
["key1", "User"],
["key2", "Guest"],
["key3", "Admin"],
]);
const res = arr.get("key2");
console.log(res);
to create an associative array with the Map
constructor.
Then we call get
with the key to get the value associated with the key.