简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM