How do I get the requiredObject data structure from the rows and columns variable? I know I need to use some higher-order array methods like map, etc. I just find the right combination

-
Posting image for code is bad practice. Is it to avoid some teacher finding his given homework online ?kriss– kriss2021-10-14 21:06:45 +00:00Commented Oct 14, 2021 at 21:06
Add a comment
|
2 Answers
const sortedColums = columns.columns.sort((a,b) => a.value - b.value).map(x=>x.name)
const output = rows.map(x => { const entry = {}; x.map((val, idx) => entry[sortedColums[idx]] = val); return entry})
1 Comment
nima
While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. You can find more information on how to write good answers in the help center: stackoverflow.com/help/how-to-answer . Good luck 🙂