xFactorSchool.com(Beta)
How to Do Examples
Python Examples
HTML Examples
Code Examples
C Code Examples
C++ Code Examples
C# Code Examples
Java Code Examples
Python Code Examples
HTML Code Examples
CSS Code Examples
JavaScript Code Examples
Online Editor
C Code Editor
C++ Code Editor
C# Code Editor
Java Code Editor
Python Code Editor
HTML Code Editor
CSS Code Editor
JavaScript Code Editor
Practice how to use map in JavaScript
JavaScript Online Editor
Run Code
More JavaScript Sample Codes
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>How to use map in JavaScript</title> <!--Script is added to write JavaScript code inside it--> <script> var loopResult = ""; //create a Map (Map is a key-value pair) with some key-value pairs const fruitsPrice = new Map([["Apple", 10], ["Banana", 5]] ); // add another key-value pair to the fruitsPrice Map fruitsPrice.set("Orange", 8); for(let [key, value] of fruitsPrice ) // loop through the fruitsPrice Map { loopResult += "<p> The price of " + key + " is $" + value + ".</p>"; } function myFunction() { document.getElementById("outPut").innerHTML = loopResult; }; </script> </head> <body> <h1>How to use map in JavaScript?</h1> <button onclick="myFunction()">Click here to see result</button> <p id="outPut"></p> </body> </html>