I utilized the lodash
library to divide arrays into chunks (batches).
let values = {
'key1' : [lotsOfValues1],
'key2' : [lotsOfValues2]
};
let keys = ['key1', 'key2'];
let arrObj = [];
keys.forEach((key) => {
arrObj.push([key] : lodash.chunk(values[key], 20)) // it will break lotsOfValues arrays into chunks of size 20
});
/* Now arrObj = [
{
key1: [[someVals1], [someVals2], [someVals3]],
},
{
key2: [[someVals4], [someVals5]],
},
];
*/
Is there a more efficient way to convert an array of Objects -
const arrObj = [
{
key1: [[someVals1], [someVals2], [someVals3]],
},
{
key2: [[someVals4], [someVals5]],
},
];
to an array of Objects where each object has individual array elements instead of an array of objects. For example -
const arrObjTransformed = [
{ key1: [someVals1] },
{ key1: [someVals2] },
{ key1: [someVals3] },
{ key2: [someVals4] },
{ key2: [someVals5] },
];
any assistance on this matter would be greatly appreciated.
I attempted to iterate through arrObj and nested loops to create a new object with each value, continuously updating the final output array.
However, I believe there might be a cleaner solution to accomplish this task.