有任何想法,我如何在Typescript或JS中分割这些:
{“AED”:“阿拉伯联合酋长国迪拉姆”,“AFN”:“阿富汗阿富汗人”,“所有人”:“阿尔巴尼亚人列克”}
我只想要这样的名字:
AED AFN ALL
答案 0 :(得分:0)
你做错了,首先修改你的object
到array of objects
,如下所示
let currencies = [
{
code: "AED",
fullName: "United Arab Emirates Dirham"
},
{
code: "AFN",
fullName: "Afghan Afghani"
},
{
code: "ALL",
fullName: "Albanian Lek"
}
];
现在你可以像
那样遍历它currencies.forEach(val => {
//use val.code to get desired currencies codes
})
答案 1 :(得分:0)
您可以使用Object.keys
(link)从某个对象中提取所有键。
var countries = { "AED": "United Arab Emirates Dirham", "AFN": "Afghan Afghani", "ALL": "Albanian Lek" }
var codes = Object.keys( countries );
console.log( codes ); // [ "AED", "AFN", "ALL" ]