Initially, I've this array:
[{
"vendorid": 1,
"vendorname": "Vendor1",
"maxfilelimit": 2,
"uploadfilename": "Voice1.xlsx"
},
{
"vendorid": 1,
"vendorname": "Vendor1",
"maxfilelimit": 2,
"uploadfilename": "Ven1_Voice.xlsx"
},
{
"vendorid": 2,
"vendorname": "Vendor2",
"maxfilelimit": 2,
"uploadfilename": "Voice2.xlsx"
},
{
"vendorid": 2,
"vendorname": "Vendor2",
"maxfilelimit": 2,
"uploadfilename": "Ven2_Voice.xlsx"
}]
I want the file names in an array with no repetition of records. So, I expect the output similar to following:
[{
"vendorid": 1,
"vendorname": "Vendor1",
"maxfilelimit": 2,
"uploadfilename": ["Voice1.xlsx", "Ven1_Voice.xlsx"]
}, {
"vendorid": 2,
"vendorname": "Vendor2",
"maxfilelimit": 2,
"uploadfilename": ["Voice2.xlsx", "Ven2_Voice.xlsx"]
}]
I found some solutions like d3.js, alaSQL but not getting output as expected
You can use
array#reduce
and inside it you can store your result in an object and then extract values usingObject.values()
.