I basically have the following string in the format:
A,B,C:D,E,F
What I am trying to achieve is a means of pairing up left hand side JavaScript variable, to the left of the “:” with the right hand side values to the right of the “:”
I would like to have the following variables set in, so that I can use in my coding, i.e:
var A = D;
var B = E;
var C = F;
I can then use the values of A,B and C as parameters into other JavaScript functions.
I have looked at the split and slice methods for this string manipulation but unsure how to pair up left hand side with right hand side values.
With this method (attaching variables to an object), you can reference variables in code without an eval statement.
If you care about the wasted comma property, check if lefts[i] is equal to a comma before you set on the object.