运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Maps</h1> <p>Being able to use objects as keys is an important Map feature:</p> <p id="demo"></p> <script> // Create Objects const apples = {name: 'Apples'}; const bananas = {name: 'Bananas'}; const oranges = {name: 'Oranges'}; // Create a Map const fruits = new Map(); // Add the Objects to the Map fruits.set(apples, 500); fruits.set(bananas, 300); fruits.set(oranges, 200); document.getElementById("demo").innerHTML = fruits.get(apples); </script> </body> </html>