Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Calling data from an object dynamicly

I’m sorry I don’t know the proper language to explain this so bear with me but…

I’m having a problem with calling/selecting a cookie that has a dynamic name from an object (I turned my cookies into a object for easy handling)

Id like it to be like this but it doesn’t work:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

cookies.lastTime + '_' + uid;

Which basically would mean ‘In cookies, get lastTime_1346234672457124’

But I’m just getting back ‘undefined_1346234672457124’ and I know why… Because this doesn’t work and its just printing a ‘undefined’ because the cookie doesn’t exist in the object (lastTime_1346234672457124 exists but lastTime doesn’t) … and then it spits out the uid which it knows.

SO. My question is, what is the proper way of going about calling this cookie from the object so that its dynamically linked to the uid? Whilst still maintaining the ‘cookies.lastTime’ method…

Thanks

>Solution :

To access object properties you can use "[]" like so:

cookies['lastTime_' + uid]

or

cookies[`lastTime_${uid}`]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading