Last Updated : Jan 1, 2023
For showing mapped key,value pair here we will showing demo within that we defined new map object with initialized pair array.
Then result printed on console using console.log() method. Using map object we can create more types string pairs, or array pairs with both whole number and strings.
Here we defined map object with key, value pairs. Map object can hold both objects and primitive values as either key or value.
When we iterate over the map object it returns the key, value pair in the same order as inserted.
It can also hold array within array and key array, value array is respective key name values.
Those are defined with example in our program when you will executes you can get some idea about that.
- <!DOCTYPE html> tag which is instruct the web browser about what version of HTML file written in and it’s not have any ending tag.
- The<html> tag is used to indicate the beginning of HTML document.
- As above shown <head> tag is contains information about webpage and external file links are declared here. <title> tag is used for set the webpage title.
- Both <head> and <title> tags having their pair end tag, so we need to close the ending tags respectively. If you’re not closed anyone of ending tag properly that is also affect the webpage result.
- <body> tag is beginning of main coding part because it contain coding of entire website blocks and elements described here.
- In map object ‘map1’ we defined array with ‘[1,2],[2,3],[4,5]’ values, here keys are ‘1,2,4’ with respective values ‘2,3,5’.
- In map object ‘map2’ we defined array within array ‘["whole numbers",[1,2,3,4]],["negative numbers",[-1,-2,-3,-4]]’ values, here keys are ‘whole numbers, negative numbers’ with respective another array values ‘[1,2,3,4],[-1,-2,-3,-4]’.
- In map object ‘map3’ we defined array pair is key array ‘["first name","last name"]’, value array ‘["dhanu","pavi"]’.
- Both </body>,</html> tags closed respectively. </body> tag indicates the end of body, Then </html> tag indicates the end of HTML document.
When we execute our program on browser we can’t see the result so we have to use that shortcut ‘ctrl+shift+j’ then result will displayed on console by console.log() method.