I'm attempting to restructure an array of objects into a new object where the label property serves as the key for multiple arrays containing objects with that same label.
Check out this JSBin function I created to map the array, but I'm unsure about the ES6 logic required to achieve the desired output.
https://jsbin.com/foyijisaku/1/edit?js,console
original array
var originalArray =
[
{
'id': 6,
'label': 'hello'
},
{
'id': 5,
'label': 'hello'
},
{
'id': 4,
'label': 'bye'
},
{
'id': 3,
'label': 'bye'
},
{
'id': 2,
'label': 'bye'
},
{
'id': 1,
'label': 'bye'
}
]
new object
var newObject =
{
'hello': [
{
'id': 6,
'label': 'hello'
},
{
'id': 5,
'label': 'hello'
},
],
'bye': [
{
'id': 4,
'label': 'bye'
},
{
'id': 3,
'label': 'bye'
},
{
'id': 2,
'label': 'bye'
},
{
'id': 1,
'label': 'bye'
},
]
}