我有一個陣列,
const headArray = ['id', 'correlationId', 'category', 'subCategory'];
我想將其轉換如下,
const columns = [{ field: 'id', headerName: 'id'},
{ field: 'correlationId', headerName: 'correlationId'},
{ field: 'category', headerName: 'category'}
{ field: 'subcategory', headerName: 'subcategory'}];
我嘗試了很多方法,但我無法做到這一點。如果有人知道方法請告訴我。
uj5u.com熱心網友回復:
我想你可以使用map來實作這一點:
const columns = headArray.map(value => ({field: value, headerName: value}));
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/440674.html
下一篇:查找陣列中包含關鍵字的元素的索引
