gpt4 book ai didi

javascript - 如何列出元素,包括值(value)、名称、面额?

转载 作者:行者123 更新时间:2023-12-01 01:30:23 24 4
gpt4 key购买 nike

我有一个像这样的对象:

  var currencyTypes = {
NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
USD: {value:0.12652, name: "United States dollar", denomination: "$" },
GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
};

我找到了一种列出所有关键对象的方法:

var keyVal = [];
for(var v in currencyTypes) keyVal.push(v);

"There are " + keyVal.length + " different currencies here: " + keyVal

这列出了所有货币类型:挪威克朗、欧元、美元、英镑

但是如何打印包含键、值、名称、面额的列表呢?我尝试了 keyVal.properties 但没有用。我试图在这里寻找解决方案,但没有找到任何东西。我想要的是看起来像这样的输出:

NOK, Norske kroner, 1 kr
EUR, European euros, 0.10733 €
and so on

最佳答案

您可以通过这种方式访问​​它。这个might帮助你。

 var currencyTypes = {
NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
USD: {value:0.12652, name: "United States dollar", denomination: "$" },
GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
};

for(var type in currencyTypes)
{
console.log("Currency: " + type);

console.log("Value: " + currencyTypes[type].value);
console.log("Name: " + currencyTypes[type].name);
console.log("Denomination: " + currencyTypes[type].denomination);

console.log("\n");
}

关于javascript - 如何列出元素,包括值(value)、名称、面额?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53339924/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com