Maps Sets - mmedrano9438/peripheral-brain GitHub Wiki

A set is a data structure used for storing data of any length and kind. Sets are iterables that have various special methods that are different from arrays.

Create a set like this: const ids = new Set();

Create a Set with a Value: const ids = new Set([3,6,9,7]); console.log(ids); // Set(4) {3,6,9,7}

Can add elements like so: const fruits = new Set(['apple'.'mango']); fruits.add('banana'); console.log(fruits) // Set(3) {'apple'. 'mango', 'banana'}

Set has really cool methods like add, has, delete, clear, entries, values, size, forEach

A map is another data structure/container used to store key-value pairs of data of any kind and length. Maps are similar to objects, but with maps, you can use anything as a key. An object, on the other hand, takes strings, symbols, and numbers as keys

Use like this: const player = new Map(['key','value'],'lawal','kamal'); console.log(player); // Map(2) { 'key' => 'value', 'lawal' => 'kamal'}

key and lawal are the keys of the map, while value and kamal are the values.