var b = '1';
How can I create a variable name using the contents of variable b? I am doing this in a each loop, so b will change.
I am wanting the final product to be something like:
var trip1 = '';
How would I accomplish something like that?
var trip + b = '';
var trip.b = '';
No, but you can do it with properties of an object:
In JavaScript, you can access properties in two ways:
Using a dot and a literal property name, e.g.
obj.trip1.Using brackets and a string property name, e.g.
obj['trip1'].In the latter case, the string doesn’t have to be a string literal, it can be the result of any expression, hence the examples above.