I've been searching for a solution for this but I can't seem to come up with an answer, so hoping someone on here can help.
I have this JSON string stored in a cookie like so:
$.cookie('serviceTrip', JSON.stringify(serviceTrip));
I need to extract a value from this cookie based on a certain variable "n" that changes based on user input. What I have is:
var n = 3;
var serviceTripValues = JSON.parse($.cookie('serviceTrip'));
var serviceTripStartValue = 'serviceTrip'+n+'start';
alert(serviceTripStartValue); //this produces serviceTrip3start
alert(JSON.parse($.cookie('serviceTrip')).serviceTrip3start); // this produces 12:00 as expected
alert(JSON.parse($.cookie('serviceTrip')).serviceTripStartValue); // this produces 'undefined'
I cant figure this out... I think it has something to do with the fact that serviceTripStartValue is a string and not an object but I don't know how to resolve it.