If I use below line, I get output='1'.
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;
Got error: undefined.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.Sign up to join this community
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];
Using the bracket notation, JS will translate
[ID] which is equal to
.ID (notice the dot). Using the dot notation, JS expects
array to be an object property, which is not.