javascript - accessing objects property dynamically (appending a string) -


i have loop in underscore

_.each(questions,function(data){  a="reason"+data.choosen; %>  <%= data.a; %>  <% count++; });  %> 

the data.choosen gets either 1 or 2 or 3 or 4. based on want display data.reason1 or data.reason2 or data.reason3 or data.reason4 property of data object.

i tried above approach doesn't work.

in javascript

x.y 

is equivalent to

x["y"] 

so can change code to

data[a] 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -