[Solved] What is the most efficient way to convert JSON with multiple objects to array in JavaScript [closed]


Simple solution with two map() operations:

const data = [{
  "week": 1,
  "lost": 10,
  "recovery_timespan": [{
    "week": 2,
    "count": 1
  }, {
    "week": 3,
    "count": 0
  }]
}, {
  "week": 2,
  "lost": 7,
  "recovery_timespan": [{
    "week": 3,
    "count": 1
  }, {
    "week": 4,
    "count": 3
  }]
}, {
  "week": 3,
  "lost": 8,
  "recovery_timespan": [{
    "week": 4,
    "count": 1
  }]
}];

const result = data.map(({lost, recovery_timespan}) => [
  lost,
  ...recovery_timespan.map(({count}) => count)
]);

console.log(result);

1

solved What is the most efficient way to convert JSON with multiple objects to array in JavaScript [closed]