我有一个关于重新组织的问题(对于这个有适当的术语吗?)jQuery中的数组。
以下是相关阵列的示例。基本上它显示了一个视频游戏列表,每个游戏都有另一个平台的嵌套数组(游戏可用的控制台)。
我想更改数组,以便删除嵌套数组并复制顶层。 我一直在尝试jQuery的$ .map无济于事。
我想从中获取
game1
xbox
ps3
PC
game2
xbox
wii
到这个
game1, xbox
game1, ps3
game1, PC
game2, xbox
game2, wii
下面是实际的数组
myCallback({
error: "OK",
limit: 5,
offset: 0,
number_of_page_results: 5,
number_of_total_results: 26,
status_code: 1,
results: [{
image: {
icon_url: "http://static.giantbomb.com/uploads/square_avatar/8/87790/1784831-box_bf2.png",
medium_url: "http://static.giantbomb.com/uploads/scale_medium/8/87790/1784831-box_bf2.png",
screen_url: "http://static.giantbomb.com/uploads/screen_medium/8/87790/1784831-box_bf2.png",
small_url: "http://static.giantbomb.com/uploads/scale_small/8/87790/1784831-box_bf2.png",
super_url: "http://static.giantbomb.com/uploads/scale_large/8/87790/1784831-box_bf2.png",
thumb_url: "http://static.giantbomb.com/uploads/scale_avatar/8/87790/1784831-box_bf2.png",
tiny_url: "http://static.giantbomb.com/uploads/square_mini/8/87790/1784831-box_bf2.png"
},
name: "Battlefield 2",
platforms: [{
api_detail_url: "http://www.giantbomb.com/api/platform/3045-94/",
id: 94,
name: "PC",
site_detail_url: "http://www.giantbomb.com/pc/3045-94/",
abbreviation: "PC"
}],
resource_type: "game"
}, {
image: {
icon_url: "http://static.giantbomb.com/uploads/square_avatar/8/87790/2409898-box_bfbc2.png",
medium_url: "http://static.giantbomb.com/uploads/scale_medium/8/87790/2409898-box_bfbc2.png",
screen_url: "http://static.giantbomb.com/uploads/screen_medium/8/87790/2409898-box_bfbc2.png",
small_url: "http://static.giantbomb.com/uploads/scale_small/8/87790/2409898-box_bfbc2.png",
super_url: "http://static.giantbomb.com/uploads/scale_large/8/87790/2409898-box_bfbc2.png",
thumb_url: "http://static.giantbomb.com/uploads/scale_avatar/8/87790/2409898-box_bfbc2.png",
tiny_url: "http://static.giantbomb.com/uploads/square_mini/8/87790/2409898-box_bfbc2.png"
},
name: "Battlefield: Bad Company 2",
platforms: [{
api_detail_url: "http://www.giantbomb.com/api/platform/3045-20/",
id: 20,
name: "Xbox 360",
site_detail_url: "http://www.giantbomb.com/xbox-360/3045-20/",
abbreviation: "X360"
}, {
api_detail_url: "http://www.giantbomb.com/api/platform/3045-35/",
id: 35,
name: "PlayStation 3",
site_detail_url: "http://www.giantbomb.com/playstation-3/3045-35/",
abbreviation: "PS3"
}, {
api_detail_url: "http://www.giantbomb.com/api/platform/3045-94/",
id: 94,
name: "PC",
site_detail_url: "http://www.giantbomb.com/pc/3045-94/",
abbreviation: "PC"
}, {
api_detail_url: "http://www.giantbomb.com/api/platform/3045-96/",
id: 96,
name: "iPhone",
site_detail_url: "http://www.giantbomb.com/iphone/3045-96/",
abbreviation: "IPHN"
}, {
api_detail_url: "http://www.giantbomb.com/api/platform/3045-121/",
id: 121,
name: "iPad",
site_detail_url: "http://www.giantbomb.com/ipad/3045-121/",
abbreviation: "IPAD"
}],
resource_type: "game"
}, {
image: {
icon_url: "http://static.giantbomb.com/uploads/square_avatar/6/63119/1711171-battlefield_play4free.jpg",
medium_url: "http://static.giantbomb.com/uploads/scale_medium/6/63119/1711171-battlefield_play4free.jpg",
screen_url: "http://static.giantbomb.com/uploads/screen_medium/6/63119/1711171-battlefield_play4free.jpg",
small_url: "http://static.giantbomb.com/uploads/scale_small/6/63119/1711171-battlefield_play4free.jpg",
super_url: "http://static.giantbomb.com/uploads/scale_large/6/63119/1711171-battlefield_play4free.jpg",
thumb_url: "http://static.giantbomb.com/uploads/scale_avatar/6/63119/1711171-battlefield_play4free.jpg",
tiny_url: "http://static.giantbomb.com/uploads/square_mini/6/63119/1711171-battlefield_play4free.jpg"
},
name: "Battlefield Play4Free",
platforms: [{
api_detail_url: "http://www.giantbomb.com/api/platform/3045-94/",
id: 94,
name: "PC",
site_detail_url: "http://www.giantbomb.com/pc/3045-94/",
abbreviation: "PC"
}],
resource_type: "game"
}, {
image: {
icon_url: "http://static.giantbomb.com/uploads/square_avatar/3/34737/1032047-bf1942_front.jpg",
medium_url: "http://static.giantbomb.com/uploads/scale_medium/3/34737/1032047-bf1942_front.jpg",
screen_url: "http://static.giantbomb.com/uploads/screen_medium/3/34737/1032047-bf1942_front.jpg",
small_url: "http://static.giantbomb.com/uploads/scale_small/3/34737/1032047-bf1942_front.jpg",
super_url: "http://static.giantbomb.com/uploads/scale_large/3/34737/1032047-bf1942_front.jpg",
thumb_url: "http://static.giantbomb.com/uploads/scale_avatar/3/34737/1032047-bf1942_front.jpg",
tiny_url: "http://static.giantbomb.com/uploads/square_mini/3/34737/1032047-bf1942_front.jpg"
},
name: "Battlefield 1942",
platforms: [{
api_detail_url: "http://www.giantbomb.com/api/platform/3045-17/",
id: 17,
name: "Mac",
site_detail_url: "http://www.giantbomb.com/mac/3045-17/",
abbreviation: "MAC"
}, {
api_detail_url: "http://www.giantbomb.com/api/platform/3045-94/",
id: 94,
name: "PC",
site_detail_url: "http://www.giantbomb.com/pc/3045-94/",
abbreviation: "PC"
}],
resource_type: "game"
}, {
image: {
icon_url: "http://static.giantbomb.com/uploads/square_avatar/8/87790/1897518-box_bf2142.png",
medium_url: "http://static.giantbomb.com/uploads/scale_medium/8/87790/1897518-box_bf2142.png",
screen_url: "http://static.giantbomb.com/uploads/screen_medium/8/87790/1897518-box_bf2142.png",
small_url: "http://static.giantbomb.com/uploads/scale_small/8/87790/1897518-box_bf2142.png",
super_url: "http://static.giantbomb.com/uploads/scale_large/8/87790/1897518-box_bf2142.png",
thumb_url: "http://static.giantbomb.com/uploads/scale_avatar/8/87790/1897518-box_bf2142.png",
tiny_url: "http://static.giantbomb.com/uploads/square_mini/8/87790/1897518-box_bf2142.png"
},
name: "Battlefield 2142",
platforms: [{
api_detail_url: "http://www.giantbomb.com/api/platform/3045-17/",
id: 17,
name: "Mac",
site_detail_url: "http://www.giantbomb.com/mac/3045-17/",
abbreviation: "MAC"
}, {
api_detail_url: "http://www.giantbomb.com/api/platform/3045-94/",
id: 94,
name: "PC",
site_detail_url: "http://www.giantbomb.com/pc/3045-94/",
abbreviation: "PC"
}],
resource_type: "game"
}],
version: "1.0"
})
答案 0 :(得分:0)
var rightArray = [];
for (game in gameArray) {
for (con in gameArray[game]) {
rightArray.push(game + ', ' + gameArray[game][con]);
}
}