Reputation: 117
i'm new to programming , i have map on my code and i want to access object key inside this map , how can i do that ???
let person = new Map();
person.set('name','ahmed');
person.set('age',25);
person.set('salary',80000);
person.set('gender','male');
person.set({name:'red',age:25},'reda')
for (let x of person)
{
console.log(`key ${x[0]} and value ` );
console.log(person.get('{name:'red',age:25}')
Upvotes: 1
Views: 45
Reputation: 22673
You should store that object somewhere, because it needs to be the exact same object, not just identical:
const key = {name: 'red', age: 25};
person.set(key, 'reda');
console.log(person.get(key));
Upvotes: 1