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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -