0

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:

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

1 Answer 1

2

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

cookies['lastTime_' + uid]

or

cookies[`lastTime_${uid}`]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.