如何用 javascript 数组中的索引替换键

how to replace keys with index in array in javascript

我有这样的数组

const data=[ {a:aa, b:bb, c:cc, d:dd, status:[key:0, value: true] },
         {a:ee, b:ff, c:gg, d:hh, status:[key:1, value: true] },
         {a:ii, b:jj, c:kk, d:ll, status:[key:1, value: true] },
       ]

我想转换成这样

const data=[{0:aa, 1:bb, 2:cc, 3:dd},
         {0:ee, 1:ff, 2:gg, 3:hh},
         {0:ii, 1:jj, 2:kk, 3:ll},
       ]

P.S。谢谢。

您可以解构不需要的属性并将值分配给对象。

const
    data = [{ a: 'aa', b: 'bb', c: 'cc', d:'dd', status: [] }, { a: 'ee', b: 'ff', c: 'gg', d: 'hh', status: [] }, { a: 'ii', b: 'jj', c: 'kk', d: 'll', status: [] }],
    result = data.map(({ status, ...o }) => Object.assign({}, Object.values(o)));

console.log(result);

const data=[ 
  {a:'aa', b:'bb', c:'cc', d:'dd', status:[{ key:0, value: true }] },
  {a:'ee', b:'ff', c:'gg', d:'hh', status:[{ key:1, value: true }] },
  {a:'ii', b:'jj', c:'kk', d:'ll', status:[{ key:1, value: true }] },
];

const output = data.reduce((acc, curr) => {
    const { status, ...rest } = curr;
    const obj = { ...Object.values(rest) }
    acc.push(obj)
    return acc;
}, [])

console.log(output)