-2

I've array like this

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] },
       ]

I want to convert it into like this

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. thank you.

5
  • 1
    what about status? what have you tried? what does not work? Commented Aug 24, 2020 at 7:45
  • It is converted by default Commented Aug 24, 2020 at 7:46
  • have you seen <stackoverflow.com/q/49424707/12499558> Commented Aug 24, 2020 at 7:50
  • Have to delete status array Commented Aug 24, 2020 at 8:08
  • status:[key:1, value: true]? That doesn't look like javascript Commented Aug 24, 2020 at 8:09

2 Answers 2

4

You could destructure unwanted properties and assign the values to an object.

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);

Sign up to request clarification or add additional context in comments.

Comments

1

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.