-1

i have following array

[{

        "games1": [{
            "playername": "1"
        }]
    },
    {

        "games2": [{
                "playername": "1"
            },
            {
                "playername": "2"
            }
        ]
    }
]

i want add new array playername2 at games1 how to push I want this type of result

        "games1": [{
                "playername": "1"
            }, {
                "playername": "2"
            }

    
Sam
  • 1,130
  • 12
  • 36
Mohit Jain
  • 15
  • 3

1 Answers1

1

You can easily do this

let myArray = [
    {
      games1: [
        {
          playername: '1',
        },
      ],
    },
    {
      games2: [
        {
          playername: '1',
        },
        {
          playername: '2',
        },
      ],
    },
  ];

  myArray[0].games1.push({playername:'2'});