1const posts = [
2 { id: 1, title: "Sample Title 1", description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit..." },
3 { id: 2, title: "Sample Title 2", description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit..." },
4 { id: 3, title: "Sample Title 3", description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit..." },
5];
6// ES2016+
7// Create new array of post IDs. I.e. [1,2,3]
8const postIds = posts.map((post) => post.id);
9// Create new array of post objects. I.e. [{ id: 1, title: "Sample Title 1" }]
10const postSummaries = posts.map((post) => ({ id: post.id, title: post.title }));
11
12// ES2015
13// Create new array of post IDs. I.e. [1,2,3]
14var postIds = posts.map(function (post) { return post.id; });
15// Create new array of post objects. I.e. [{ id: 1, title: "Sample Title 1" }]
16var postSummaries = posts.map(function (post) { return { id: post.id, title: post.title }; });
1var miMapa = new Map();
2
3var claveObj = {},
4 claveFunc = function () {},
5 claveCadena = "una cadena";
6
7// asignando valores
8miMapa.set(claveCadena, "valor asociado con 'una cadena'");
9miMapa.set(claveObj, "valor asociado con claveObj");
10miMapa.set(claveFunc, "valor asociado with claveFunc");
11
12miMapa.size; // 3
13
14// obteniendo los valores
15miMapa.get(claveCadena); // "valor asociado con 'una cadena'"
16miMapa.get(claveObj); // "valor asociado con claveObj"
17miMapa.get(claveFunc); // "valor asociado con claveFunc"
18
19miMapa.get("una cadena"); // ""valor asociado con 'una cadena'"
20 // porque claveCadena === 'una cadena'
21miMapa.get({}); // undefined, porque claveObj !== {}
22miMapa.get(function() {}) // undefined, porque claveFunc !== function () {}
23
24var myMap = new Map();
25myMap.set("bar", "foo");
26
27myMap.delete("bar"); // Retorna true. Eliminado con éxito.
28myMap.has("bar"); // Retorna false. El elemento "bar" ya no está presente.
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
10
11