0

If I start with an empty object, designed to hold a description and then an array of values (objects):

var obj = { "description" : "description",
            "value"       : [ {} ] 
          };

I can successfully add the required objects dynamically if they're nested together, like so:

obj.value[i] = { "Key1" : Parseddata[i][1],
                 "Key2" : Parseddata[i][2], 
                 "Key3" : Parseddata[i][3]
               };

but how can I add each object into the array separately (that is, not nested together in the same object)? For example, If start with:

obj.value[i] = { "Key1" : Parseddata[i][1] };

and then want to add Key2, Key3 in separate steps?

lithic
  • 181
  • 9

1 Answers1

1

Try this.

obj.value[i] = {};
obj.value[i]["Key1"] =  Parseddata[i][1];
obj.value[i]["Key2"] =  Parseddata[i][2];
obj.value[i]["Key3"] =  Parseddata[i][3];
easywaru
  • 1,073
  • 9
  • 17
  • Thanks, that works well enough, except that the values added (Parseddata[i][1] and so on) should be numeric but are instead stored as strings. – lithic Sep 18 '14 at 11:07