I have an array of objects like this below.
[
{
product_id: 4,
product_name: "Samsung",
category_name: "Tv and home appliance",
is_Available: 1
},
{
product_id: 8,
product_name: "Apple",
category_name: "Home gadgets",
is_Available: 1
},
{
product_id: 9,
product_name: "Verifone",
category_name: "Electronics",
is_Available: 0
}
]
I want to split this array into two based on is_Available flag value. So i did like this using reduce.
const formmattedResponse = data.reduce((arr,el) => {
if(el.is_Available === 1) {
arr.push({...el});
}
return arr;
},[]);
But, i need this type of formatted data like below based on above data array
{
availableData: [{
product_id: 4,
product_name: "Samsung",
category_name: "Tv and home appliance",
is_Available: 1
},
{
product_id: 8,
product_name: "Apple",
category_name: "Home gadgets",
is_Available: 1
}
],
notAvailableData: [{
product_id: 9,
product_name: "Verifone",
category_name: "Electronics",
is_Available: 0
}
]
}