Yondaru
Yondaru

Reputation: 87

Access Key in Associative array which is stored in variable

I am currently dealing with this problem. I have an associative array imageDict={}. The key to this imageDict is another Object called image and value is yet another associative array, with string as Key and array as value. So imageDict[image] = {}, and imageDict[image]["string"] = [].

The problem I have is that the key image is an object with some key/values stored in it aswell for example, width,height,top,left and so on. And at some point I store imageDict[image] into var animationQueue and send it as parameter to function animation(animationQueue), where I access its values as animationQueue["string"].... But what I would like to do is also access the Key image which is hidden in animationQueue since animationQueue = imageDict[image] and change some of its values. Is it possible to do this?

Upvotes: 0

Views: 42

Answers (1)

TheEllis
TheEllis

Reputation: 1736

If you need access to the image object, why not just pass it as a second parameter to your function function animation(animationQueue, image), or are you not able to change the animation function? I do not believe there is a way to pass the value of an associate array to a function, as you are, and from the value to get the key from the value. The value does not inherently store a reference to the key.

Upvotes: 1

Related Questions