Aggressive
Aggressive

Reputation: 93

How to get JSON object length in jquery?

i have two JSON objects inside a JSON array as below

array.put(resObj);

array.put(resObjPrd);

i'm returning this array as a Jquery ajax response.Can anyone please explain me how can i get the length of second object using jquery? Here is my Jquery ajax code.

$.ajax({
    type: 'POST',
    url: "fetch",
    dataType: 'json',
    data: {
        clientidedit: clientidedit
    },
    success: function(data) {
        alert(data[1]);

    }
});

Upvotes: 2

Views: 3259

Answers (1)

guest271314
guest271314

Reputation: 1

Could use JSON.stringify() to retrieve string representation of Object , then return .length of stringified object

var obj = {"abc":123};
var objStr = JSON.stringify(obj);
console.log(objStr.length)

Upvotes: 1

Related Questions