Compare all array item into JSON array object
const filterArray = ['Ford', 'Fiat'];
const showrooms = [{
"Name": "Mark Auto",
"Location": "Delhi",
"Cars": ['Ford', 'BMW', 'Fiat']
},
{
"Name": "Cardekho",
"Location": "Mumbai",
"Cars": ['Ford', 'Fiat']
},
{
"Name": "Tata Arena",
"Location": "Pune",
"Cars": ['Ford', 'BMW']
},
{
"Name": "Nexa Showroom",
"Location": "Noida",
"Cars": ['Suzuki', 'Ford', 'Tata', 'Fiat']
}
]
I write code to filter data but not working.
const result = this.showrooms.filter(c=> this.filterArray.includes(c.Cars)).map(a=>a.Name);
Desired Output
['Mark Auto', 'Cardekho', 'Nexa Showroom']