2

If I use below line, I get output='1'.

data.d.results[i].ID;

But instead of giving hardcoded ID, Is there any way to pass by variable?

I already tried like:

var array=["ID","Title"];
data.d.results[i].array[0];

Got error: undefined.

4

The ID is an object property, so you need to access it like an object property using the square bracket notation instead of dot notation:

var array = ["ID", "Title"];

data.d.results[i][array[0]];

Using the bracket notation, JS will translate [array[0]] into [ID] which is equal to .ID (notice the dot). Using the dot notation, JS expects array[0] to be an object property, which is not.

Not the answer you're looking for? Browse other questions tagged or ask your own question.