I am looking for a way to convert an array of objects into a 2D array (array of arrays). I have tried using map and Object.keys(), but I need to organize the values differently. Specifically, I want to push the first value of each object into the first array, the second value into the second array, and so on. Thank you in advance for your assistance.
The desired output
[
['2', '5', '8', '10', '12'],
['4', '10', '16', '20', '24'],
['6', '15', '24', '30', '36'],
['10', '25', '40', '50', '60']
]
The current output
[
['2', '4', '6', '10'],
['5', '10', '15', '25'],
['8', '16', '24', '40'],
['10', '20', '30', '50'],
['12', '24', '36', '60']
]
let obj = [
{
line1: '2',
line2: '4',
line3: '6',
line4: '10'
}, {
line1: '5',
line2: '10',
line3: '15',
line4: '25'
}, {
line1: '8',
line2: '16',
line3: '24',
line4: '40'
}, {
line1: '10',
line2: '20',
line3: '30',
line4: '50'
}, {
line1: '12',
line2: '24',
line3: '36',
line4: '60'
}
];
var output = obj.map(function(obj) {
return Object.keys(obj).map(function(key) {
return obj[key];
});
});
console.log(output);