Sunday, 29 September 2013

using variable to define json object name

using variable to define json object name

I'm having a problem that I think is very easy to solve, but I can't seem
to find an answer for it in my searches.
I have a bunch of json objects that I'm using. Right now I get at the info
like so for example:
for(image in data.everfi_commons.images) {
alert(data.everfi_commons.images[image]);
}
what I'd like to do instead is instead of having the name 'everfi_commons'
I'd like to just use a javascript variable that I've set up like so:
current_project = $(this).attr("id"); // this value is 'everfi_commons'
and then I thought you could just do data.current_project.images[image]
but this doesn't seem to work and I don't really understand why, any
insight would be helpful!

No comments:

Post a Comment