Answers for "convert json to 2d array"

0

convert json to 2d array

function jsonArrayTo2D(arrayOfObjects){
  let header = [],
      AoA = [];
  arrayOfObjects.forEach(obj => {
    Object.keys(obj).forEach(key => header.includes(key) || header.push(key))
    let thisRow = new Array(header.length);
    header.forEach((col, i) => thisRow[i] = obj[col] || '')
    AoA.push(thisRow);
  })
  AoA.unshift(header);
  return AoA;
}
Posted by: Guest on January-22-2020

Code answers related to "convert json to 2d array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language