1let contacts = new Map()
2contacts.set('Jessie', {phone: "213-555-1234", address: "123 N 1st Ave"})
3contacts.has('Jessie') // true
4contacts.get('Hilary') // undefined
5contacts.set('Hilary', {phone: "617-555-4321", address: "321 S 2nd St"})
6contacts.get('Jessie') // {phone: "213-555-1234", address: "123 N 1st Ave"}
7contacts.delete('Raymond') // false
8contacts.delete('Jessie') // true
9console.log(contacts.size) // 1
1array.map((item) => {
2 return item * 2
3} // an example that will map through a a list of items and return a new array with the item multiplied by 2
1// Map decalaration in javaScript
2const obj1 = { name: 'ismail' };
3const obj2 = { name: 'sulman' };
4const obj3 = { name: 'naeem' };
5
6firstMap = new Map([
7 [
8 [obj1, [{ date: 'yesterday', price: '10$' }]], // using object as a key in the map and object inside the array
9 [obj2, [{ date: 'today', price: '100$' }]]
10 ]
11]);
12firstMap.set(obj3, [{ date: "yesterday", price: '150$' }]); //pushing the obj to the Map
13
14// iterating the Map
15for (const entry of firstMap.entries()) {
16 console.log(entry);
17};
18
19console.log(firstMap);
20
21firstMap.delete(obj3);
22console.log(firstMap);
1let utilisateurs = new Map()
2
3utilisateurs.set('Mark Zuckerberg' ,{
4 email: 'mark@facebook.com',
5 poste: 'PDG',
6})
7
8utilisateurs.set ('bill Gates',{
9 email: 'billgates@notes.com' ,
10 poste : 'sauver le monde' ,
11
12})
13
14console.log(utilisateurs);
1let map = new Map()
2map['bla'] = 'blaa'
3map['bla2'] = 'blaaa2'
4
5console.log(map) // Map { bla: 'blaa', bla2: 'blaaa2' }
6
1// Use map to create a new array in memory. Don't use if you're not returning
2const arr = [1,2,3,4]
3
4// Get squares of each element
5const sqrs = arr.map((num) => num ** 2)
6console.log(sqrs)
7// [ 1, 4, 9, 16 ]
8
9//Original array untouched
10console.log(arr)
11// [ 1, 2, 3, 4 ]