Skip to content

Instantly share code, notes, and snippets.

@belocer
Last active October 6, 2020 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save belocer/b35135b3f678d87573266f1c4672af2f to your computer and use it in GitHub Desktop.
Save belocer/b35135b3f678d87573266f1c4672af2f to your computer and use it in GitHub Desktop.
Объект 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