数据对象
var data = { "93288240": { "enHomeTeam": "GS Warriors (SLAMDUNKVV) Esports", "enAwayTeam": "DEN Nuggets (Siegfried) Esports", "enVsTeams": "GS Warriors (SLAMDUNKVV) Esports @ DEN Nuggets (Siegfried) Esports", "enLeague": "Ebasketball Live Arena - 4x5mins", "restTime": "00:00", "score": "53-63", "eventId": "93288240", "hasSubscrib": "1", "homeTeam": "GS Warriors (SLAMDUNKVV) Esports", "awayTeam": "DEN Nuggets (Siegfried) Esports", "vsTeams": "GS Warriors (SLAMDUNKVV) Esports @ DEN Nuggets (Siegfried) Esports", "league": "篮球电竞球场现场赛 - 4x5分钟" }, "93302140": { "enHomeTeam": "HOU Rockets (Aphex) Esports", "enAwayTeam": "DAL Mavericks (BoBBy) Esports", "enVsTeams": "HOU Rockets (Aphex) Esports @ DAL Mavericks (BoBBy) Esports", "enLeague": "Ebasketball Live Arena - 4x5mins", "restTime": "5:00", "score": "62-59", "eventId": "93302140", "hasSubscrib": "1", "homeTeam": "HOU Rockets (Aphex) Esports", "awayTeam": "DAL Mavericks (BoBBy) Esports", "vsTeams": "HOU Rockets (Aphex) Esports @ DAL Mavericks (BoBBy) Esports", "league": "篮球电竞球场现场赛 - 4x5分钟" } }
读取方式A
var eventId = [],homeTeam=[]; Object.keys(data).forEach(function (key) { //console.log(key, data[key]); console.log(data[key]); eventId.push(data[key].eventId); homeTeam.push(data[key].homeTeam); }); console.log(eventId); console.log(homeTeam);
读取方式B
for (let i in data) { //console.log(i, ":", data[i]); //console.log(data[i]); eventId.push(data[i].eventId); homeTeam.push(data[i].homeTeam); }
Done!