I'm trying to transform the following array of objects into an object that contains the label property as the key to multiple arrays of objects containing that same key as the property.
Here's a JSBin of a function that maps the array but I'm not sure about the ES6 logic I would use to get the output I want.
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'
},
]
}