I have the following sample data:
let abc = [
{
endPointScrape: 'https://www.example.com/computer/component/keyboards-and-mice/microsoft-surface-pen-silver/p/100008669',
mainCatagoryScrape: 'Computer',
subCatagoryScrape: 'Component',
subSubCatagoryScrape: 'Keyboards and mice',
itemsDataScrape: {
itemName: 'Microsoft Surface Pen, Silver',
itemOrignalPrice: '399',
itemCurrentPrice: '299',
itemDiscount: '100'
}
},
{
endPointScrape: 'https://www.example.com/computer/component/keyboards-and-mice/microsoft-surface-arc-mouse-sc-bluetooth-xz-ar-hdwr-light-grey/p/100008664',
mainCatagoryScrape: 'Computer',
subCatagoryScrape: 'Component',
subSubCatagoryScrape: 'Keyboards and mice',
itemsDataScrape: {
itemName: 'Microsoft Surface Arc Mouse SC Bluetooth XZ/AR Hdwr, Light Grey',
itemOrignalPrice: '319',
itemCurrentPrice: '239',
itemDiscount: '80'
}
},
{
endPointScrape: 'https://www.example.com/white-goods/washing-machines/topload/classpro-top-load-fully-automatic-washing-machine-12kg-white/p/100055634',
mainCatagoryScrape: 'White goods',
subCatagoryScrape: 'Washing machines',
subSubCatagoryScrape: 'Topload',
itemsDataScrape: {
itemName: 'ClassPro Top Load Fully Automatic Washing Machine, 12kg, White',
itemOrignalPrice: '1849',
itemCurrentPrice: '1349',
itemDiscount: '500'
}
},
{
endPointScrape: 'https://www.example.com/white-goods/washing-machines/topload/classpro-top-load-fully-automatic-washing-machine-9kg-white/p/100055635',
mainCatagoryScrape: 'White goods',
subCatagoryScrape: 'Washing machines',
subSubCatagoryScrape: 'Topload',
itemsDataScrape: {
itemName: 'ClassPro Top Load Fully Automatic Washing Machine, 9kg, White',
itemOrignalPrice: '1499',
itemCurrentPrice: '1099',
itemDiscount: '400'
}
}
]
Now the above array of objects i want to sort them within an array if they have the same mainCatagoryScrape, subCatagoryScrape and subSubCatagoryScrape. So as my output looks somewhat like below as the end result.
enpointScrape as an array of strings and itemdatascrape as an array of objects (respectively) that contains items with same maincatagory,subcatagory and subsubcatagory.
let abc = [
{
endPointScrape: [
'https://www.example.com/computer/component/keyboards-and-mice/microsoft-surface-pen-silver/p/100008669',
'https://www.example.com/computer/component/keyboards-and-mice/microsoft-surface-arc-mouse-sc-bluetooth-xz-ar-hdwr-light-grey/p/100008664'],
mainCatagoryScrape: 'Computer',
subCatagoryScrape: 'Component',
subSubCatagoryScrape: 'Keyboards and mice',
itemsDataScrape: [{
itemName: 'Microsoft Surface Pen, Silver',
itemOrignalPrice: '399',
itemCurrentPrice: '299',
itemDiscount: '100'
},
{
itemName: 'Microsoft Surface Arc Mouse SC Bluetooth XZ/AR Hdwr, Light Grey',
itemOrignalPrice: '319',
itemCurrentPrice: '239',
itemDiscount: '80'
}]
},
{
endPointScrape: [
'https://www.example.com/white-goods/washing-machines/topload/classpro-top-load-fully-automatic-washing-machine-12kg-white/p/100055634',
'https://www.example.com/white-goods/washing-machines/topload/classpro-top-load-fully-automatic-washing-machine-9kg-white/p/100055635'],
mainCatagoryScrape: 'White goods',
subCatagoryScrape: 'Washing machines',
subSubCatagoryScrape: 'Topload',
itemsDataScrape: [{
itemName: 'ClassPro Top Load Fully Automatic Washing Machine, 12kg, White',
itemOrignalPrice: '1849',
itemCurrentPrice: '1349',
itemDiscount: '500'
},
{
itemName: 'ClassPro Top Load Fully Automatic Washing Machine, 9kg, White',
itemOrignalPrice: '1499',
itemCurrentPrice: '1099',
itemDiscount: '400'
}]
}]
i dont have access to all the catagories and they differ. hence i want to sort the same catagory items by creating a new array which matches with other object values and create unique maincategory,subcategory and subsubcatagory object with arrays of all those with same values. i tried few solutions but nothing came out to be definitive.