Andrei C.
Andrei C.

Reputation: 57

dynamical variable instead of jquery's method

I learn jquery not long time. Help please to put variable instead object method.

return {
    label: item.MYVariable,
}

I need instead of MYVariable put dynamic variables.

Upvotes: 1

Views: 60

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337560

Assuming I've understood your question correctly, you can use bracket notation to access the variables, like this:

var foo = 'MYVariable';
return {
    label: item[foo];
}

Upvotes: 2

Related Questions