javascrip maps code example
Example 1: js map constructor
let myMap = new Map([
[1, 'one'],
[2, 'two'],
[3, 'three'],
])
Example 2: maps in javascript
const obj1 = { name: 'ismail' };
const obj2 = { name: 'sulman' };
const obj3 = { name: 'naeem' };
firstMap = new Map([
[
[obj1, [{ date: 'yesterday', price: '10$' }]],
[obj2, [{ date: 'today', price: '100$' }]]
]
]);
firstMap.set(obj3, [{ date: "yesterday", price: '150$' }]);
for (const entry of firstMap.entries()) {
console.log(entry);
};
console.log(firstMap);
firstMap.delete(obj3);
console.log(firstMap);