I need help. i need filter a json object like this...
data =
[
{
"Empresa": "PLANTA",
"Sucursal": "AEROPUERTO",
"Producto": "PIZZA",
"Categoria": "RAPIDA"
"Total": 84,
"FPago": "TERMINAL",
"SegCliente": "SIN SEGMENTO",
"Origen": "MOSTRADOR"
},
{
"Empresa": "RIVERA",
"Sucursal": "CIRCUITO",
"Producto": "PASTEL",
"Categoria": "BOCADILLOS",
"Total": 152,
"FPago": "INALAMBRICA",
"SegCliente": "SIN SEGMENTO",
"Origen": "MOSTRADOR"
}
,...
]
I get a array from filtres from Categoria like this ['BOCADILLOS','POSTRES'...] and another to empresa like ['PLANTA',...] I built these arrays dynamically
How can i filter data.Categoria with values in ['BOCADILLOS','POSTRES'...]
ty for help
CodePudding user response:
You can use Array.filter
let categories = ['BOCADILLOS', 'POSTRES'];
let filtered = data.filter((item) => categories.includes(item.Categoria));