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
Post a Comment