How to push new array in react native object

103 views Asked by At

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"
            }

    
1

There are 1 answers

1
Sina Kordestani On

You can easily do this

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

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