gpt4 book ai didi

javascript - ANGULARJS 用空数组填充数组对象

转载 作者:行者123 更新时间:2023-12-03 06:42:13 29 4
gpt4 key购买 nike

所以我有这个 json

"inventory": {
"data": {
"0": {
"id": 637,
"upgrade": 0,
"bind": 0,
"slot": 0,
"name": "Slot Extender (Low)",
"desc": null
},
"4": {
"id": 3247,
"upgrade": 0,
"bind": 0,
"slot": 4,
"name": "Lamp of Dazzlement (Lv. 4)",
"desc": null
},
"7": {
"id": 637,
"upgrade": 0,
"bind": 0,
"slot": 7,
"name": "Slot Extender (Low)",
"desc": null
},
"8": {
"id": 1454,
"upgrade": 0,
"bind": 0,
"slot": 8,
"name": "Vampiric Earring +7",
"desc": null
},
"11": {
"id": 12,
"upgrade": 0,
"bind": 0,
"slot": 11,
"name": "Return Stone",
"desc": null
},
"12": {
"id": 2425,
"upgrade": 0,
"bind": 0,
"slot": 12,
"name": "Vital Potion (Lv. 2)",
"desc": null
},
"14": {
"id": 3094,
"upgrade": 0,
"bind": 0,
"slot": 14,
"name": "Holy Water of Critical Strike (30 min)",
"desc": null
},
"16": {
"id": 3247,
"upgrade": 0,
"bind": 0,
"slot": 16,
"name": "Lamp of Dazzlement (Lv. 4)",
"desc": null
},
"20": {
"id": 10,
"upgrade": 0,
"bind": 0,
"slot": 20,
"name": "Upgrade Core (Medium)",
"desc": null
},
"22": {
"id": 10,
"upgrade": 0,
"bind": 0,
"slot": 22,
"name": "Upgrade Core (Medium)",
"desc": null
},
"23": {
"id": 2444,
"upgrade": 0,
"bind": 0,
"slot": 23,
"name": "Strike Potion (Lv. 1)",
"desc": null
},
"24": {
"id": 19,
"upgrade": 9,
"bind": 4,
"slot": 24,
"name": "Citrine Orb",
"desc": null
},
"26": {
"id": 124,
"upgrade": 15,
"bind": 1,
"slot": 26,
"name": "Aramid Battlesuit",
"desc": null
},
"28": {
"id": 2704,
"upgrade": 0,
"bind": 0,
"slot": 28,
"name": "Weapon Option Scroll (High)",
"desc": null
},
"29": {
"id": 214,
"upgrade": 15,
"bind": 4,
"slot": 29,
"name": "Aramid Battleboots",
"desc": null
},
"44": {
"id": 169,
"upgrade": 13,
"bind": 4,
"slot": 44,
"name": "Aramid Battlegloves",
"desc": null
},
"47": {
"id": 663,
"upgrade": 0,
"bind": 0,
"slot": 47,
"name": "Force Regen. Potion (Lv. 1)",
"desc": null
},
"48": {
"id": 1,
"upgrade": 0,
"bind": 0,
"slot": 48,
"name": "Upgrade Core (High)",
"desc": null
},
"56": {
"id": 2342,
"upgrade": 0,
"bind": 0,
"slot": 56,
"name": "Holy Water of Fighter",
"desc": null
},
"59": {
"id": 2381,
"upgrade": 0,
"bind": 0,
"slot": 59,
"name": "Enchant Safeguard (Highest)",
"desc": null
},
"64": {
"id": 2338,
"upgrade": 0,
"bind": 0,
"slot": 64,
"name": "Holy Water of Vitality",
"desc": null
},
"65": {
"id": 1116,
"upgrade": 0,
"bind": 0,
"slot": 65,
"name": "Snow Ice MP Potion",
"desc": null
},
"66": {
"id": 5,
"upgrade": 0,
"bind": 0,
"slot": 66,
"name": "HP Potion (Lv. 3)",
"desc": null
},
"68": {
"id": 1381,
"upgrade": 0,
"bind": 0,
"slot": 68,
"name": "Copper Coin",
"desc": null
},
"72": {
"id": 320,
"upgrade": 0,
"bind": 0,
"slot": 72,
"name": "Life Absorb Ring +2",
"desc": null
},
"74": {
"id": 582,
"upgrade": 0,
"bind": 0,
"slot": 74,
"name": "Force Core (Low)",
"desc": null
},
"75": {
"id": 2,
"upgrade": 0,
"bind": 0,
"slot": 75,
"name": "Force Core (High)",
"desc": null
},
"76": {
"id": 2339,
"upgrade": 0,
"bind": 0,
"slot": 76,
"name": "Holy Water of Speed",
"desc": null
},
"80": {
"id": 3278,
"upgrade": 0,
"bind": 0,
"slot": 80,
"name": "Skill Book (Split Specialty Stage 3)",
"desc": null
},
"82": {
"id": 3276,
"upgrade": 0,
"bind": 0,
"slot": 82,
"name": "Skill Book (Sword Splitter)",
"desc": null
},
"84": {
"id": 3277,
"upgrade": 0,
"bind": 0,
"slot": 84,
"name": "Skill Book (Split Specialty Stage 2)",
"desc": null
},
"86": {
"id": 34,
"upgrade": 5,
"bind": 1,
"slot": 86,
"name": "Citrine Crystal",
"desc": null
},
"96": {
"id": 3293,
"upgrade": 0,
"bind": 0,
"slot": 96,
"name": "Minesta Training Book Chapter 15",
"desc": null
},
"105": {
"id": 1214,
"upgrade": 0,
"bind": 0,
"slot": 105,
"name": "Upgrade Core (Highest)",
"desc": null
},
"106": {
"id": 1214,
"upgrade": 0,
"bind": 0,
"slot": 106,
"name": "Upgrade Core (Highest)",
"desc": null
},
"107": {
"id": 1214,
"upgrade": 0,
"bind": 0,
"slot": 107,
"name": "Upgrade Core (Highest)",
"desc": null
},
"128": {
"id": 1116,
"upgrade": 0,
"bind": 0,
"slot": 128,
"name": "Snow Ice MP Potion",
"desc": null
},
"129": {
"id": 2345,
"upgrade": 0,
"bind": 0,
"slot": 129,
"name": "Holy Water of Flawless Defense",
"desc": null
},
"130": {
"id": 1116,
"upgrade": 0,
"bind": 0,
"slot": 130,
"name": "Snow Ice MP Potion",
"desc": null
},
"131": {
"id": 1115,
"upgrade": 0,
"bind": 0,
"slot": 131,
"name": "Snow Star HP Potion",
"desc": null
},
"132": {
"id": 1115,
"upgrade": 0,
"bind": 0,
"slot": 132,
"name": "Snow Star HP Potion",
"desc": null
},
"133": {
"id": 1115,
"upgrade": 0,
"bind": 0,
"slot": 133,
"name": "Snow Star HP Potion",
"desc": null
},
"134": {
"id": 1116,
"upgrade": 0,
"bind": 0,
"slot": 134,
"name": "Snow Ice MP Potion",
"desc": null
},
"142": {
"id": 2,
"upgrade": 0,
"bind": 0,
"slot": 142,
"name": "Force Core (High)",
"desc": null
},
"196": {
"id": 1275,
"upgrade": 0,
"bind": 0,
"slot": 196,
"name": "Periodical Remote shop card",
"desc": null
}
}

这是某个 Angular 色库存中某些元素的 json 对象。关键基本上是该库存中的元素槽 ID。我想要的是根据 AngularJS 中缺少的键填充空数组。例如,如果您采用前 2 个项目,第一个项目有 0 键,第二个项目有键 4,因此缺少 1,2,3,我想用这些缺少的键填充空数组。我希望重复这个过程,直到最多 255 个数组!任何人都可以帮我提供代码或其他东西吗?

最佳答案

你可以这样做:

for( var i=0;i<255;i++){
if(inventory.data[i] == undefined){
inventory.data[i] = {};
}
}

我假设您想要将空对象分配给不存在的键。

关于javascript - ANGULARJS 用空数组填充数组对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37905741/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com