i have a json object that gets returned by an AJAX request and I am having some trouble with the .length
because it keeps returning undefined
. Just wondering if I'm using it right:
console.log(data.length);
console.log(data.phones.length);
They both return undefined
even though they are valid objects.
Update:
Sample of the JSON object returned:
{"reqStatus":true,"phones":{"one":{"number":"XXXXXXXXXX","type":"mobile"},"two":{"number":"XXXXXXXXXX","type":"mobile"}}}
Consider using underscore.js. It will allow you to check the size i.e. like that:
try this
You can use something like this
you dont need to change your JSON format.
replace:
with: