Last active
August 31, 2021 14:37
-
-
Save tararoutray/fc36b0b6ad85b0d2fde5efdd7a621169 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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