JSFiddle - React, Tailwind, and code Playground
by Dmitri Ganenco
JavaScript
const arr = [
{
"id": "1",
"Name": "Coke 500ml",
"Price": "80",
"Quantity": "50",
"Category": "Beverages"
},
{
"id": "2",
"Name": "Cake",
"Price": "150",
"Quantity": "40",
"Category": "Appetizer"
},
{
"id": "3",
"Name": "Beef Ribs",
"Price": "100",
"Quantity": "50",
"Category": "Side Items"
},
{
"id": "4",
"Name": "Cabbage Salad",
"Price": "50",
"Quantity": "30",
"Category": "Salads"
},
{
"id": "5",
"Name": "Cake",
"Price": "150",
"Quantity": "30",
"Category": "Appetizer"
},
{
"id": "6",
"Name": "Beef Ribs",
"Price": "100",
"Quantity": "30",
"Category": "Side Items"
}
];
function filterArrayByCategory(category) {
return arr.filter(el => el.Category === category);
}
console.log(filterArrayByCategory('Appetizer'));