Is there any short way to move all array elements inside object of objects. For Ex- I have an array like
var a = [
{
'a': 'a',
'test' : 'test'
},
{
'b' : 'b',
'test' : 'test'
}
]
I want to move this array elements inside object so it looks like:
var a = {
"test" : {
0: {
'a' : 'a',
'test' : 'test'
},
1: {
'b' : 'b',
'test' : 'test'
}
}
};
"test" inside a should not be an array, as i am creating XML with this data. How can i accomplish with javascript ?
arr.reduce((result,item,index)=>{result[index]=item;return result;},{})