How to add a new object to another within an array

I have an array which looks like this:

array = [
         {code1: 
          {
           number: 2,
           name: "e"
          }
         },
         {code2: 
          {
           number:2,
           name: "u"
          }
         }
         ]

and I want to add the following as a new object to say "code1" without changing the data it now has.

{
number: 3,
name: "j"
}

how can I do it? Thank you!

39 thoughts on “How to add a new object to another within an array”

Leave a Comment