Loop object that in the array and in the another object

后端 未结 2 1772
鱼传尺愫
鱼传尺愫 2021-01-25 20:49

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

相关标签:
2条回答
  • 2021-01-25 21:18

    Do it like this

    import React from 'react'
    
    export default class YourComponent extends React.Component {
        render() {
            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"
                    }
                }
            ]
    
            let newArr = arr.map((data) => {
                return data.CoinInfo.FullName
            })
            console.log('new array', newArr);
            return (
                <div>
                </div>
            )
        }
    }
    
    0 讨论(0)
  • 2021-01-25 21:19

    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);

    0 讨论(0)
提交回复
热议问题