I want transform an array of objects into 2D array (array of arrays). I try with map and Object.keys(), but I want push the first value of each objects into the first array, the second value of each objects into the second array, etc ... Thank you for your answers.
The good result
[
['2', '5', '8', '10', '12'],
['4', '10', '16', '20', '24'],
['6', '15', '24', '30', '36'],
['10', '25', '40', '50', '60']
]
The actual result
[
['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);