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.

closed as off-topic by Hitodama, Benny Skogberg Jul 14 '16 at 19:21

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions not specific to SharePoint are off-topic here, but can be asked on Stack Overflow." – Hitodama, Benny Skogberg
If this question can be reworded to fit the rules in the help center, please edit the question.

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.