我有以下结构。我需要在 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);
关于javascript - 循环数组和另一个对象中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53979774/