循环对象在数组和另一个对象中 [英] Loop object that in the array and in the another object

查看:53
本文介绍了循环对象在数组和另一个对象中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下结构。我需要获得内部价值并通过React。我想我需要获得一系列值,例如:['Bitcoin','Etherium'...]并通过它进行映射。我该如何实现呢?

  let arr = [
{
CoinInfo:{
Id:1182,
名称:BTC,
FullName:比特币,
内部:BTC,
ImageUrl:/ media / 19633 / btc.png,
Url:/ coins / btc / overview
}
},
{
CoinInfo:{
Id:7605,
名称:ETH,
FullName:以太坊,
内部: ETH,
ImageUrl:/ media/20646 / eth_logo.png,
Url:/ coins / eth / overview
}
]


解决方案

以下是使用硬币名称数组的方法 Array.prototype。 map()

  const arr = [{CoinInfo:{Id:1182,Name:BTC,FullName:比特币,内部:BTC,ImageUrl:/ media / 19633 / btc.png,Url:/ coins / btc / overview}},{CoinInfo:{Id :7605,名称:ETH,FullName:以太坊,内部:ETH,ImageUrl:/ media/20646 /eth_logo.png,Url:/ coins / eth / overview}}]; const coinNames = arr.map(x => x.CoinInfo.FullName); console.log(coinNames);  


i have the following structure. I need to get Internal value and through in the React. I think i need to get an array of values, for example: ['Bitcoin', 'Etherium'...] and map through it. How can i implement it?

 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"
      }
]

解决方案

Here's how you'd get an array of coin names using 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);

这篇关于循环对象在数组和另一个对象中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆