Sebastian Herrmann
A software-developing peep.
ES6 offers nice new features:
… but also Sets and Maps!
… aka fancier arrays!
const providers = new Set();
iterable object
providers.add('amazon');
providers.add('netflix');
providers.add('netflix');
providers.delete('netflix');
providers.size; // => 1
providers.has('amazon'); // => true
providers.has('itunes'); // => false
providers.values(); // => {'amazon'}
const countries = ['de', 'us', 'us'];
const countriesSet = new Set(countries);
Cooperating with regular arrays:
// or super-short via ES6 destructuring 🚀
const uniqueCountries = [...new Set(countries)];
// => {'de', 'us'}
// unique values!
→ not so relevant for us
… aka minimalistic objects!
const filters = new Map();
filters.set('genres', ['action', 'scifi']);
filters.get('genres'); // => ['action', 'scifi']
filters.has('min_price'); // => false
filters.size; // => 1
(no prototype clutter)
How to handle those iterable objects?!
filters.entries(); // => {['genres', ['action', 'scifi']]}
filters.keys(); // => {'genres'}
filters.values(); // => {['action', 'scifi']}
filters.forEach((value, key) => {
// do stuff...
});
for ([key, value] of filters) {
// do stuff...
}
Same story as for WeakSets…
→ not so relevant for us
Source: ES6 compat-table
Tutorial for maps and sets:
Thanks for listening!
By Sebastian Herrmann
What do we gain from using ES6's new sets and maps?