I have following two-dimensional array code
var questions = [
['How many states are in the United States?', 50],
['How many continents are there?', 7],
['How many legs does an insect have?', 6]
];
and converted version of it to array object
var questions = [
{ question: 'How many states are in the United States?', answer: 50 },
{ question: 'How many continents are there?', answer: 7 },
{ question: 'How many legs does an insect have?', answer: 6 }
];
and have corresponding for loops.
for (var i = 0; i < questions.length; i += 1) {
question = questions[i][0];
answer = questions[i][1];
response = prompt(question);
response = parseInt(response);
if (response === answer) {
correctAnswers += 1;
correct.push(question);
} else {
wrong.push(question);
}
}
and
for (var i = 0; i < questions.length; i += 1) {
question = questions[i].question;
answer = questions[i].answer;
response = prompt(question);
response = parseInt(response);
if (response === answer) {
correctAnswers += 1;
}
}
What is the actual difference between two-dimensional array and array object? Would it affect running for loop faster to sort data ? How would I know which one is better ?
questions[i][1]what is that?questions[i].answeractually makes sense.