Skip to content

Instantly share code, notes, and snippets.

@tararoutray
Last active August 31, 2021 14:37
Show Gist options
  • Save tararoutray/fc36b0b6ad85b0d2fde5efdd7a621169 to your computer and use it in GitHub Desktop.
Save tararoutray/fc36b0b6ad85b0d2fde5efdd7a621169 to your computer and use it in GitHub Desktop.
// Let's create a new map object
const userDetails = new Map();
// Now assign some data in key-value pair
// To assign data use the set() function
userDetails.set('firstname', 'Bettie');
userDetails.set('lastname', 'Whitlock');
userDetails.set('age', 24);
// To get a key of the above declared map, use the get() function
console.log(userDetails.get('firstname'));
// To print the size, use the .size attribute
console.log(userDetails.size);
// To delete a key from the declared map use the delete() function
userDetails.delete('age');
// You can assign keys with same name with different data types
userDetails.set(1, 'key of type number');
userDetails.set('1', 'key of type string');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment