Reputation: 31709
I have this lines at my ajax request:
success: function (response) {
var result = $.parseJSON(response);
Since the response is an array of key/value pairs, how to know the number of pairs?
Upvotes: 1
Views: 1167
Reputation: 2183
If it's an Array like Object you can use the following:
console.log(Object.keys(result).length)
If it's just an Array you can use:
console.log(result.length);
Upvotes: 2
Reputation: 38502
Try this way because .length
only works with array
not with object
. so
var count = 0;
for(var key in json)
if(json.hasOwnProperty(key))
count++;
alert(count);
N.B: if it is an array
then go with .length
alert(result.length);
Upvotes: 0