改造数组只有1个键[重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

使用来自已知视频游戏的JSON / Array中的一些数据。我接近创建一个只有本地化名称的新数组,但不能完全正确。我错过了什么:

const endpoint = './heroes-org.json'
let heroes = []
let renamed = []

fetch(endpoint)
  .then(text => text.json())
  .then(data => heroes.push(...data.result.heroes))
  .then(() => {
    for(i = 0; i < heroes.length; i++){
        // renamed += heroes[i].localized_name
        //heroes.map(function){
        //}
        setTimeout(function(){
            console.log(renamed)
        }, 2000)
    }})

map函数是一个摆脱每个数组元素不必要的键的想法。

另外,如果我只是在Chrome控制台中控制日志heroes,请告诉我:

enter image description here

看起来不太对劲。为什么我的数组分为0-99等?

我最终想要只有一个包含所有115个英雄名字的数组。

javascript json ajax ecmascript-6
1个回答
0
投票

它只是Chrome的一个功能。 Chrome将阵列拆分为由100个元素组成的较小部分,以便于调试。看长度属性,它的价值是115 :)

© www.soinside.com 2019 - 2024. All rights reserved.