I need to return the string with category and type together when use input the type id(which is unique) , I am pretty much done with that but I am unable to fetch root category . My solution return 'Terrace' but I need 'Rural / Terrace'.
I think I am making things over complicated
let obj =[
{
category: 'Residential',
category_id: 1,
types: [{name: 'House', id: 1},{name: 'Townhouse / Villa', id: 3},{name: 'House and Land', id: 5},{name: 'Duplex', id: 4},{name: 'Land', id: 6},{name: 'Terrace', id: 16},{name: 'Apartment/Unit', id: 2},{name: 'Relocatable', id: 7}]
},
{
category: 'Commercial',
category_id: 2,
types: [{name: 'Office', id: 12},{name: 'House', id: 8},{name: 'Land', id: 9},{name: 'Shop', id: 10},{name: 'Factory', id: 11}]
},
{
category: 'Rural',
category_id: 3,
types: [{name: 'House', id: 17},{name: 'House and Land', id: 14},{name: 'Land', id: 13},{name: 'Terrace', id: 15}]
}
];
console.log(obj.map(o=>o.types).reduce((acc, val) => acc.concat(val), []).find(inner_obj=>inner_obj.id==15).name);