javascript - 循环在数组和另一个对象中的对象
问题描述
我有以下结构。我需要在 React 中获得内部价值并通过。我想我需要获取一组值,例如: ['Bitcoin', 'Etherium'...] 并通过它进行映射。我该如何实施?
let arr = [
{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
]
解决方案
这是您如何使用获得一组硬币名称的方法Array.prototype.map()
const arr = [{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
}
];
const coinNames = arr.map(x => x.CoinInfo.FullName);
console.log(coinNames);
推荐阅读
- sql-server - 计算 SQL Server 中同一列的时间差
- r - 按唯一行计算重复行
- python - NetworkX 访问具有多个节点属性的节点
- c# - iOS上的Xamarin字典空指针异常
- coldfusion - lucee错误说Entity不存在,即使组件存在
- python - Python telnetlib 自动响应提示
- neo4j - 我可以使用 neo4j 数据库而不在我的系统中安装它并且不安装它吗?
- tsql - 外部应用如何使用从连接表中选择
- javascript - 如何在反应钩子中有条件
- angularjs - 当从模型数组中添加模型元素时,AngularJS - ng-repeat 列表无法使用 groupby 过滤器工作