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

Got error: undefined.


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


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.