I am filtering a javascript object..
[{
title: 'example1',
categorySlug: 'cat-1',
categoryName: 'hello1'
}
{
title: 'example2',
categorySlug: 'cat-2',
categoryName: 'hello2'
}
{
title: 'example3',
categorySlug: 'cat-1',
categoryName: 'hello1'
}]
I need the object as below
[{
categorySlug: "cat1",
categoryName: "hello1",
data: [{
{
title: "example1",
categorySlug: 'cat-1',
categoryName: 'hello1'
},
{
title: "example1",
categorySlug: 'cat-1',
categoryName: 'hello1'
}
}]
},
{
categorySlug: "cat2",
categoryName: "hello2",
data: [{
{
title: "example2",
categorySlug: 'cat-2',
categoryName: 'hello2'
}
}]
}
]
I need to filter the object. I have tried with many way but I have faield to filter the object.
#I have added one more category And I nedd to filter like that.
categorySlugandcategoryNamealways the same in pairs? (i.e.cat-2always together withhello2etc.)