Skip to content

Instantly share code, notes, and snippets.

@kironroy
Created May 23, 2023 01:12
Show Gist options
  • Save kironroy/d07bd104cf996cdc5b172bab51e242dc to your computer and use it in GitHub Desktop.
Save kironroy/d07bd104cf996cdc5b172bab51e242dc to your computer and use it in GitHub Desktop.
maps.js
// maps are more useful then sets
// maps have key-value pairs
// maps keys can have any type
const restaurantMap = new Map();
restaurantMap.set('name', "Vini's Curry House");
restaurantMap.set(1, 'Mumbai, India');
console.log(restaurantMap.set(2, 'Paris, France'));
restaurantMap
.set('categories', ['Italian', 'Pizzeria', 'Vegetarian', 'Organic'])
.set('open', 11)
.set('close', 13)
.set(true, 'We are open')
.set(false, 'We are closed')
.set(document.querySelector('h1'), "Heading");
console.log(restaurantMap.get('name'));
console.log(restaurantMap.get(true));
console.log(restaurantMap.get('categories'));
const time = 21;
console.log(restaurantMap.get(time > restaurantMap.get('open') && time <restaurantMap.get('close')));
console.log(restaurantMap.has('categories'));
restaurantMap.delete(2);
restaurantMap.set([1,2], 'Test')
console.log(restaurantMap);
console.log(restaurantMap.size);
// restaurantMap.clear();
console.log(restaurantMap);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment