2

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]);

    }
});
7
  • "how can i get the length of second object" Is resObjPrd an Array ? data[1].length ? Commented Nov 28, 2015 at 16:17
  • i'm getting undefined while alert(data[1].length); Commented Nov 28, 2015 at 16:19
  • "getting undefined while alert(data[1].length)" Is resObjPrd an Array ? Commented Nov 28, 2015 at 16:19
  • resObjPrd and resObj are two JSON objects..and i'm adding it to a json array "array". i want to get the length of 2nd object Commented Nov 28, 2015 at 16:21
  • Object {} does not have .length property . Though could use JSON.stringify() to get string representation of Object , then return .length of stringified object Commented Nov 28, 2015 at 16:21

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.