Grouping a object value inside n level nested array

I have an array like this. How to group all child Ids into an array? My solution below is not giving me all child elements. Where is the mistake? and suggest me any other ways

const data = {
  name: '1',
  id: '05f770d5',

  child: [
    {
      name: '2',
      id: '0ecfc8e1',
      child: [
        {
          name: '3',
          id: '2e1eb75c',
          child: [],
        },
      ],
    },
    {
      name: '1c',
      id: 'b9ee9864',
      child: [
        {
          name: '8',
          id: '575f4760',
          child: [],
        },
      ],
    },
  ],
};

let array1 = [];

function sumChild(data) {
  data.child.forEach((data) => {
    array1.push(data.id);
    sumChild(data?.child[0]);
  });

  return array1;
}

sumChild(data);

console.log(array1);

Answer

function sumChild(data) {
  data.child?.forEach((data) => {
    array1.push(data.id);
    sumChild(data);
  });

  return array1;
}