The main idea is that the map should get a specific value from the array. if you do not return anything on the map by default, undefined will return and you will get undefined. Use the filter to obtain the desired object and use the map to obtain the desired property of this object
var mappingobj = {"custom":[{"head":"202","sub":["302","303"]},{"head":"203","sub":["102"]}],"spec":[]};
var subids = mappingobj.custom.filter(function(o, i) {
if(o.head==202 && o.head){
return o;
}
}).reduce((acc,elem)=>{acc.push(...elem.sub); return acc;},[]);
console.log(subids);
Run codeHide result source
share