The Internet

Log In or Register

 to be sorted in ascending order?

in a sorted list

Bookmark

0 Points

▲ good image

bad image ▼

Ask AI on The Internet

Question: John [ { id: 0, key: 'City', value: 'Texas', preference: 0 }, { id: 0, key: 'Phone number', value: '456', preference: 0 }, { id: 0, key: 'address', value: 'Bangalore', preference: 0 } ] admin [] Steve [ { id: 0, key: 'City', value: 'ND', preference: 0 }, { id: 0, key: 'Phone number', value: '789', preference: 0 } ] how to get c=[John,Texas,456,Bangalore], d=[admin] and e=[Steve,ND,789]

Asked by naveen

0 Points

Log In or Register to Vote

?</code> I want to get c=[John,Texas,456,Bangalore], d=[admin] and e=[Steve,ND,789] from the above data. I tried with for of loop and if condition but it not worked. Can anyone help me how can i achieve this? Thanks A: You can use <code>.map()</code> and spread operator <code>...</code> to format data in the way you want <code>const data = { John: [{ id: 0, key: 'City', value: 'Texas', preference: 0 }, { id: 0, key: 'Phone number', value: '456', preference: 0 }, { id: 0, key: 'address', value: 'Bangalore', preference: 0 } ], admin: [], Steve: [{ id: 0, key: 'City', value: 'ND', preference: 0 }, { id: 0, key: 'Phone number', value: '789', preference: 0 } ] } let c = [] c.push(Object.keys(data)[0], ...Object.values(data)[0].map(o =&gt; o.value)) let d = [] d.push(Object.keys(data)[1]) let e = [] e.push(Object.keys(data)[2], ...Object.values(data)[2].map(o =&gt; o.value)) console.log('c: ', c) console.log('d: ', d) console.log('e: ', e)</code>

Answered by text-davinci-003

Jan. 25, 2023, 7:09 a.m.

0 Points

Log In or Register to Vote

A new large language model has been made available since this question was asked.

To generate an updated answer from the new model, click the button below.

Think your answer is better than the AI's? Post it below.

Please log in or sign up to post your answer.

Question Tags
This article was generated in part by one of OpenAI’s large-scale language-generation model, answering user naveen's question. Images were generated with OpenAI's AI model, DALL·E 2. The Internet takes ultimate responsibility for the content of this publication.
If you want your question answered by an AI, click here.

Published: Wednesday, January 25, 2023

Comment Section



USD