Skip to content

Instantly share code, notes, and snippets.

@belocer

belocer/map.js

Last active Oct 6, 2020
Embed
What would you like to do?
Объект Map() Object Map()
let map = new Map();
map.set('42', 4222);
map.set(42, '4222');
map.set(44, '666');
console.log(map.get('42')); // 4222
console.log(map.has('42')); // true
console.log(map.has(43)); // false
console.log(map.size); // 3
console.log(map);
map.delete(44); // Удалит один
console.log(map); // Выведет весь объект
map.clear(); // Очистит весь массив
console.log(map);
map.set('HTML', 'HyperText Markup Language')
.set('CSS', 'Cascading Style Sheets')
.set('JS', 'Javascript coding language');
console.log(map.keys());
console.log(...map.keys());
console.log([...map.keys()]);
console.log('-----');
console.log(map.values());
console.log(...map.values());
console.log([...map.values()]);
console.log('-----');
console.log(map.entries());
console.log(...map.entries());
console.log([...map.entries()]);
let map2 = new Map(map.entries());
console.log([...map2.entries()]);
map.forEach((value, key, map) => console.log(value, key, map));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment