سؤال

I have a for loop that runs over a JSON object and returns the properties in the console. What I am trying to do is return also the value of that property in the console.

This is the code

   for (var i in response) {
       console.log(i); //return the property to the console
    }

How can I get the value of response.i and not just the name of the property?

هل كانت مفيدة؟

المحلول

Try the following :

console.log(response[i]); 

You are iterating throw the object, but i is number of the property in the collection, not the property value.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top