Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm new to JavaScript and I'm having trouble understanding this sample code for a Q&A mobile app. The following code is for the question page of the mobile app:

for(var i = 0; i < question['answers'].length; i++){
    var answer = question['answers'][i],

I've searched the mobile app's entire code and this is the only place ['answers'] is found.

question is a controller and has already been defined, but ['answers'] --plural-- has never been defined prior to being used in this for loop.

Anyone understand how this is possible?

share|improve this question
7  
I don't know what's confusing you but question['answers'] is the same as question.answers. – dystroy 9 mins ago
And if there's no error in the execution here, then it has been defined. – dystroy 9 mins ago
I don't understand what your question is to be honest. If there is no error, question.answers is valid... – BenM 9 mins ago
1  
Did you search the ENTIRE app code or Javascript code only? It may be defined in non-JS code which prints dynamically generated JS. Or it could be returned via AJAX call from some service inside JSON object. – DVK 4 mins ago
2  
Nobody can guess where the data come from. Of course we can propose to look at them using console.log but that's about all. I suppose we should close this. – dystroy 4 mins ago
show 5 more comments

closed as not a real question by Derek Henderson, Benjamin Gruenbaum, Quentin, Matt, Sani Huttunen 2 mins ago

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.