ts map code example
Example 1: 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);
Example 2: typescript create map
var map = new Map();
map.set('1', 'Ail');
map.set(1, 'testvalue');
console.log( "Value 1= " + map.get(1));
console.log( "Key is Present in the Map = " + map.has(3) );
console.log( "Delete value from Map = " + map.delete(1) );
Example 3: javascript map
const numbers = [0,1,2,3];
console.log(numbers.map((number) => {
return number;
}));