DevLog.at

Irene's Devlogs

Developer, developer, developer, developer.

ProfileFollowing

Today, I discovered Maps in JS.

Not to be confused with the good ol JS Object {}, Maps provide a way to enumerate in the order of insertion key value pairs.

See below!

const map = new Map();

map.set('cat', 'tofu');

map.set('dog', 'kobe');

console.log(map); //{'cat'-> 'tofu', 'dog' -> 'kobe'}

Objects have all their keys as strings, but Maps don't have the same restriction. So adding different types as keys can be useful in certain cases.

map.set(1, 'number key!');

console.log(map); //{'cat'-> 'tofu', 'dog' -> 'kobe', 1 -> 'number key!'}

2m

Some other functions you can call on your Map include:

map.set('cat','tofu');

map.has('cat'); //true

map.get('cat'); //tofu

map.delete('dog');

map.has('dog'); //false

2m

Until it didn't.

2m

I've realized I'm terrible at Binary Trees.

2m

Verified this during today's phone screen.

2m