繁体   English   中英

循环数组和另一个对象中的对象

[英]Loop object that in the array and in the another object

我有以下结构。 我需要获得内部价值并在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); 

像这样做

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM