Using a variable as a hash key in Coffeescript -


let's have hash in coffeescript:

exercises =   stretchedprayer:     name: "stretched prayer"     sound: "28-stretched-prayer"   bandstretch:     name: "band stretch"     sound: "13-band-stretch" 

i can correctly name of first exercise following code:

exercises.stretchedprayer.name 

what want call same name know exercise want variable extracted id on web page.

in other words, if have variable such

myexercise = "stretchedprayer" 

how can name of practice in hash using variable?

just use square brackets, in javascript.

exercises[myexercise].name 

object[property] same object.<<property's value>>


Comments

Popular posts from this blog

php - Dynamic url re-writing using htaccess -

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -