codemarch
codemarch

@codemarch

19 Tweets Aug 29, 2022
Learn Maps in JavaScript.
Thread🧵
1. What is Map?
➡️The JavaScript Map object is used to map keys to values.
➡️It stores each element as key-value pair.
2. How to create a Map?
➡️ Passing an Array to a new Map()
3. Map.set()
➡️ Create a Map and use Map.set()
➡️ It can also be used to change existing Map values.
4. Map.get()
➡️ The get() method gets the value of a key in a Map.
5. Map.size
➡️ The size property returns the number of elements in a Map
6. Map.delete()
➡️ The delete() method removes a Map element
7. Map.clear()
➡️ The clear() method removes all the elements from a Map
8. Map.has()
➡️ The has() method returns true if a key exists in a Map.
9. typeof
➡️ Maps are Objects that's why typeof returns object.
10. instanceof
➡️ Use the instanceof operator to check if an object is a Map.
11. for of
➡️ Allows you to iterate over iterable objects .
12. forEach
➡️The forEach() method calls a function for each element.
13. Map.keys()
➡️The keys() method returns an iterator object with the keys in a Map
14. Map.values()
➡️The values method returns an iterator object with the values in a Map
15. Map.entries()
➡️The entries() method returns an iterator object with the [key,values] in a Map.
16. Converting map to array.
If you enjoyed reading this thread, please do the following:
1. Like the thread❤️
2. Retweet the first tweet.🔃
3. Follow me and enable notifications: ✅
@CodeMarch
Thank you for reading all the way through.
Download our free JavaScript Resources ebook Here:
codemarch.gumroad.com

Loading suggestions...