Answer the question
In order to leave comments, you need to log in
Why is the for loop not working?
There is an ajax request, in success I try to use the for loop, it does not work, that is, it does not go inside it. Foreach works, but I need for.
Answer the question
In order to leave comments, you need to log in
If you do something like
this in a loop and response is not an array but an object with properties, then response.length will be undefined and the loop will not be executed.
For example, try doing the following in the console:
var response = {key1: 'property1', key2: 'property2'};
console.log( response.length); // undefined
console.log( Object.keys(response).length); // 2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question