I am struggling with a particular Javascript problem and I hope someone can help.
I have a list of name and value pairs, e.g.:
Apple 50
Banana 60
Grape 70
Apple 40
Orange 30
I am trying to create a Javascript object out of these values:
var myObj = {};
and then for all items in the list:
myObj[name] = value;
but as you can see some names are in the list more than once (e.g. Apple), so in this case I would like to add it to the same property of the object by converting the value in the object to an array and adding the new value to the array.
So myObj would contain:
Apple = [50,40]
Banana = 60
Grape = 70
Orange = 30
Anyone help?
Thanks,
AJ
Like this:
If some of the values are already arrays, they will be flattened, not nested.