javascript - 从对象键创建 JavaScript 数组
问题描述
我有以下 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 |
})
解决方案
supportedCurrencies = [
{
"currencyCode":"USD",
},
{
"currencyCode":"CAD",
},
{
"currencyCode":"GBP",
}
]
const info = supportedCurrencies.map(el => el.currencyCode).join("|")
console.log(info)
推荐阅读
- python - 自动为图像设置标签
- php - Mysql 使用 php 按大小获取产品
- ssh - 如何使用 RDP 和 SSH 设置鳄梨酱会话记录
- c++ - C++ 可变参数模板包扩展为多种模板类型(例如 std::shared_ptr)是否可能?
- php - parse_ini_file 返回的数据是否总是与给定文件的顺序相同?
- typescript - Discord.js 空值检查在 TypeScript 中不起作用
- c# - 获取 SharePoint 列表中行的所有版本
- r - 如何计算 R 中回归模型的风险差异?
- java - GET 请求 - 重定向到另一个页面并保留参数
- responsive - 为什么不同的移动网站以 m 扩展名打开