I have the below object which has array of objects. I want format this object to object of Array of arrays
var object1 = {
"Usa": [{
"period": "2018-11-03T00:00:00.000+0000",
"qty": 1
}, {
"period": "2018-11-04T00:00:00.000+0000",
"qty": 2
}],
"india": [
{
"period": "2018-19-03T00:00:00.000+0000",
"qty": 2
}, {
"period": "2018-19-04T00:00:00.000+0000",
"qty": 3
}
]
}
export const createDataPoint = (period, qty) => {
return [
Date.now(time),
Math.round((Math.random() * 100) * 2) / 2 + quantity,
];
};
export function createData(object1) {
let data = [];
let total = [];
Object.keys(object1).map(function(item, index) {
object1[item].map(function(item2, index2) {
data.push(createDataPoint(item2.period, item2.qty));
})
object1[item] = data
})
// console.log(object1)
return object1;
}
But the output is, in every array there are 4 arrays instead of 2 respective arrays. Which means in every array, i am getting total arrays of size 4.
Expected output is
var object1={
"Usa":[
["123245235",1],
["21423435",2]
],
"india":[
["234325436",2],
["23422464",3]
]
}