B
Bosconian
I'm trying to output the contents of an array of associative arrays in
JavaScript. I'm looking for an equivalent of foreach in PHP.
Example:
var games = new Array();
var teams = new Array();
teams["team1"] = "Lakers";
teams["score1"] = "78";
teams["team1"] = "Sacramento";
teams["score2"] = "88";
games[0] = teams;
var teams = new Array();
teams["team1"] = "Houston";
teams["score1"] = "94";
teams["team1"] = "Dallas";
teams["score2"] = "84";
games[1] = teams;
Desired output:
Lakers
78
Sacramento
88
Houston
94
Dallas
84
I tried (unsuccessfully):
document.open();
for (theGame in games) {
for (i in theGame) {
document.writeln(i + " = " + theGame + "<br>");
}
}
document.close();
Thanks in advance.
JavaScript. I'm looking for an equivalent of foreach in PHP.
Example:
var games = new Array();
var teams = new Array();
teams["team1"] = "Lakers";
teams["score1"] = "78";
teams["team1"] = "Sacramento";
teams["score2"] = "88";
games[0] = teams;
var teams = new Array();
teams["team1"] = "Houston";
teams["score1"] = "94";
teams["team1"] = "Dallas";
teams["score2"] = "84";
games[1] = teams;
Desired output:
Lakers
78
Sacramento
88
Houston
94
Dallas
84
I tried (unsuccessfully):
document.open();
for (theGame in games) {
for (i in theGame) {
document.writeln(i + " = " + theGame + "<br>");
}
}
document.close();
Thanks in advance.