<html>
<body>
<h1>JavaScript 对象</h1>
<h2>Object.entries() 方法</h2>
<p>Object.entries() 返回一个对象的键值对数组。</p>
<p>使用 Object.entries() 可以轻松地在循环中使用对象:</p>
<p id="demo"></p>
<script>
const fruits = {Bananas: 300, Oranges: 200, Apples: 500};
let text = "";
// 遍历键值对数组,并构建字符串
for (let [fruit, amount] of Object.entries(fruits)) {
text += fruit + ": " + amount + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>