score:1

Accepted answer
const input = [
    {
        id: 1,
        service: 1001,
        country: {
            id: 1,
            countryname: 'India'
        },
        ts: 1597758281
    },
    {
        id: 2,
        service: 1002,
        country: {
            id: 2,
            countryname: 'USA'
        },
        ts: 1597758283
    }
];
const i = 0;
const newId = 2;

const output = [
  ...input.slice(0, i),
  {
    ...input[i],
    country: { id: newId, countryname: input[i].country.countryname }
  },
  ...input.slice(i + 1),
];
console.log(output);

Related Query

More Query from same tag