what is the best way to convert an object of arrays to an array of objects and vice-versa
{
category : [\'a\',\'b\',\'c\'],
title : [\'e\',\'f\',\'g\'],
Here is solution using reduce
method and arrow
function.
var obj={
category : ['a','b','c'],
title : ['e','f','g'],
code : ['z','x','v']
}
var result=obj[Object.keys(obj)[0]].reduce((a,b,i)=>{
var newObj={};
Object.keys(obj).forEach(function(item){
newObj[item]=obj[item][i];
});
return a.concat(newObj);
},[]);
console.log(result);