javascript 如何将一个对象添加到数组中的另一个对象

How to add an object to another object in array in javascript

import React from 'react';
import ReactExport from 'react-data-export';

const ExcelFile = ReactExport.ExcelFile;
const ExcelSheet = ReactExport.ExcelFile.ExcelSheet;

ExcelData = [{
        columns:
            [
                [{ title: "Header1" }],
                [{ title: "Header2" }],
                [{ title: "Header3" }],
                [{ title: "Header4" }],
            ],
    data:
        [
          [ {..}, {..}, {..}, {..} ],
          [ {..}, {..}, {..}, {..} ],
          [ {..}, {..}, {..}, {..} ],
          [ {..}, {..}, {..}, {..} ],  
        ],    

}]

1.if 我想将另一个对象 FinalData 附加到给定格式的数据数组,如对象数组,在 Header1 下,从 Data01 到 Data04 的数据同样应该来。我们该怎么做? FinalData 的格式将为

FinalData = [
                [{ value: "Data01" },
                 { value: "Data02" },
                 { value: "Data03" }
                 { value: "Data04"  }],
                [{ value: "Data21" },
                 { value: "Data22" },
                 { value: "Data23" }
                 { value: "Data24"  }],
                [{ value: "Data31" },
                 { value: "Data32" },
                 { value: "Data33" }
                 { value: "Data34"  }],
                [{ value: "Data41" },
                 { value: "Data42" },
                 { value: "Data43" }
                 { value: "Data44"  }],
            ]

我想要将FinalData映射到ExcelData中的数据的函数,格式应该是一样的。因为我需要在 dataSet={ExcelData} 中传递相同的结构以获得预期的输出 Excel.

export default function ExcelExportTwo() {
    return (
        <div>
            <ExcelFile element={<button>ExcelExportThree</button>}>
                <ExcelSheet dataSet={ExcelData} name="Organization" />
            </ExcelFile>
        </div>
    );
}

Excel Sheet 中的预期输出应该是

我不确定这是否是您需要的。

const ExcelData = [
  {
    columns: [
      [{title: 'Header1'}],
      [{title: 'Header2'}],
      [{title: 'Header3'}],
      [{title: 'Header4'}],
    ],
    data: [],
  },
];

const FinalData = [
  [
    {value: 'Data11'},
    {value: 'Data12'},
    {value: 'Data13'},
    {value: 'Data14'},
  ],
  [
    {value: 'Data21'},
    {value: 'Data22'},
    {value: 'Data23'},
    {value: 'Data24'},
  ],
  [
    {value: 'Data31'},
    {value: 'Data32'},
    {value: 'Data33'},
    {value: 'Data34'},
  ],
  [
    {value: 'Data41'},
    {value: 'Data42'},
    {value: 'Data43'},
    {value: 'Data44'},
  ],
];

const result = [{...ExcelData[0], data: [...FinalData]}];
console.log(result);