I have an object like this:
const phrases = {
1:{
sentenceID: 1,
reference: "some phrase",
},
2:{
sentenceID: 2,
reference: "It was in",
},
3:{
sentenceID: 2,
reference: "Grand Pabbie's visions",
},
4:{
sentenceID: 2,
reference: "visions",
},
5:{
sentenceID: 3,
reference: "another phrase of a sentence",
},
6:{
sentenceID: 3,
reference: "and this is one more phrase",
},
};
And I want to create an array of objects in which each object in the new array is based on same sentenceIDs...
In other words I want the objects in the new array with same sentenceIDs.
So the desired result would be this:
result = [
{
1: {
sentenceID: 1,
reference: "some phrase",
},
},
{
2: {
sentenceID: 2,
reference: "It was in",
},
3: {
sentenceID: 2,
reference: "Grand Pabbie's visions",
},
4: {
sentenceID: 2,
reference: "visions",
},
},
{
5: {
sentenceID: 3,
reference: "another phrase of a sentence",
},
6: {
sentenceID: 3,
reference: "and this is one more phrase",
},
}
]
1in an object of its own, but2,3,4are collected in a single object?sentenceIDsentenceIDas the key, and the value is the new grouped objects you want to create in the result.