我有以下JavaScript数组:
supportedCurrencies = [
{
"currencyCode":"USD",
},
{
"currencyCode":"CAD",
},
{
"currencyCode":"GBP",
}
]
我的目标是获取currencyCode值并创建一个数组(例如[USD,CAD,GBP ...],然后将这些数组与| ...连接起来,以获得最终的字符串输出USD | CAD | GBP >
supportedCurrencies.map(key => {
// Map through JS object
// Get currencyCode values
// Create new array with values
// Join these values with |
})
答案 0 :(得分:2)
supportedCurrencies = [
{
"currencyCode":"USD",
},
{
"currencyCode":"CAD",
},
{
"currencyCode":"GBP",
}
]
const info = supportedCurrencies.map(el => el.currencyCode).join("|")
console.log(info)