1

I have an ajax response which returns an array of two Json objects. The second object contains dynamic keys, which i'm using below to get the values. The problem is that i'm confused about how i can get it in ajax response. I know the starting name of the key and it ends with numbers from 1,2 or 3.. corresponding to the dynamic keys..Normally we get the value by giving data[1].checkservice but here the key is dynamic.

$.ajax({
                   type: 'POST',
                   url: "fetch",
                   dataType: 'json',
                   data:  {clientidedit:clientidedit},
                   success: function(data) {
                      count = Object.keys(data[1]).length/6;   
                   for(i=1;i<=count;i++){
                     abc ='checkservice'+i;
                     console.log("abc is :::"+abc)
                     console.log("value is "+data[1].abc);
                   }
    });

By printing console.log("value is "+data[1].checkservice1) i'm getting exact value. But while printing console.log("value is "+data[1].abc) i'm getting undefined.

0

1 Answer 1

1

You can try this

console.log("value is "+data[1][abc])

here your var abc stores string inside it and you are trying to access it as a property of an object thats why it's returning undefined

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.