Dies ist ein Array, das die Frage zu Index 0 und Auswahlmöglichkeiten von 1-4 enthält und dann auf Index 5 die Antwort enthält. Ich möchte auf diese Indexnummern einzeln zugreifen, aber nicht.Zugriff auf mein 2-D-Array in Javascript
questionbank = [
["Which city is the capital of Pakistan", "Islamabad", "Karachi", "Lahore", "Quetta", "Islamabad"],
["Which city is the capital of U.A.E", "Dubai", "Abu Dhabi", "Sharjah", "Ras Al-Khaimah", "Dubai"],
["Which city is the capital of United States of America", "Austin", "Washington DC", "Boston", "Colorado", "Washington DC"],
["Which city is the capital of UK", "London", "Manchester", "Leeds", "Sunderland", "London"],
["Which city is the capital of Kuwait", "Kuwait City", "Salmiya", "Jahra", "Tokyo", "Kuwait City"],
["Which city is the capital of Saudi Arabia", "Riyadh", "Mecca", "Madinah", "Jeddah", "Riyadh"],
["Which city is the capital of India", "Mumbai", "Delhi", "Bareilly", "Calcutta", "Mumbai"],
["Which city is the capital of Afghanistan", "Kabul", "Kandahar", "Herat", "Jalalabad", "Kabul"],
["Which city is the capital of Ireland", "Dublin", "Belfast", "Cork", "Limerick", "Dublin"]
];
function next_question() {
text = questionbank[0, 0];
alert(text);
}
next_question();
Das Problem ist, wenn ich [0,0] in der Anordnung der ganze Satz aufrufen, anstatt nur ein Element in dem Array kommt. Mein Array ist eine Sammlung von Fragen zu Position 0 und der Sammlung von Auswahlmöglichkeiten in den anderen Positionen. Kannst du mir bitte sagen, wie man immer nur auf ein Element des Arrays zugreifen kann?
Dank! Du bist großartig :) –
Schöne Erklärung über den Komma-Operator. –