I want to remove TextRow and add a string(true) to JSON in NodeJs. I have added below my code.
NodeJs Code:
function groupBy(objectArray, property) {
return objectArray.reduce(function (acc, obj) {
let key = obj[property]
if (!acc[key]) {
acc[key] = []
}
acc[key].push(obj)
return acc
}, {})
}
group data :
[
TextRow { name: '/products', email: '111@gmail.com' },
TextRow { name: '/products', email: '222@gmail.com' },
TextRow { name: '/sales', email: '111@gmail.com' },
TextRow { name: '/sales', email: '222@gmail.com' },
TextRow { name: '/sales', email: '333@gmail.com' },
TextRow { name: '/sales', email: '444@gmail.com' },
TextRow { name: '/finance', email: '333@gmail.com' },
TextRow { name: '/finance', email: '444@gmail.com' },
]
My output:
{
'/products': [
TextRow { name: '/products', email: '111@gmail.com' },
TextRow { name: '/products', email: '222@gmail.com' },
],
'/sales': [
TextRow { name: '/products', email: '111@gmail.com' },
TextRow { name: '/products', email: '222@gmail.com' },
TextRow { name: '/products', email: '333@gmail.com' },
TextRow { name: '/products', email: '444@gmail.com' },
],
'/products': [
TextRow { name: '/products', email: '333@gmail.com' },
TextRow { name: '/products', email: '444@gmail.com' },
],
}
Output Should be:
{
'/products': [
{
'111@gmail.com': true,
'222@gmail.com': true,
}
],
'/sales': [
{
'111@gmail.com': true,
'222@gmail.com': true,
'333@gmail.com': true,
'444@gmail.com': true,
}
],
'/finance': [
{
'333@gmail.com': true,
'444@gmail.com': true,
}
]
}