I would like to achieve the following by filtering and mapping the two array of nested objects using the map and filter in the angular.
I have got one solution in regards to my last question to filter based on specific property.
but I am not sure how to filter different objects based on different properties.
I want to filter some object using id property and some using the val... is it possible?
- i would like to compare type1 and type2 based on val
- i would like to compare type1 and type2 data object using dataid
- i would like to compare type3/type4 based on id..
const obj1 = [
{
"val":"type1",
"removed":"N",
"id":1,
"data":[
{
"label":"type1-a",
"removed":"N",
"dataid":16
},
{
"label":"type1-b",
"removed":"N",
"dataid":26
}
]
},
{
"val":"type2",
"removed":"N",
"id":2,
"data":[
{
"label":"type2-a",
"removed":"N",
"dataid":12
},
{
"label":"type2-b",
"removed":"N",
"dataid":34
}
]
},
{
"val":"type3",
"removed":"N",
"id":124,
"label":"type3-label1"
},
{
"val":"type4",
"removed":"N",
"id":126,
"label":"type4-label1"
},
{
"val":"type4",
"removed":"N",
"id":128,
"label":"type4-label2"
}
]
const obj2 = [
{
"val":"type1new",
"removed":"N",
"id":1
"data":[
{
"label":"type1new",
"removed":"N",
"dataid":16
},
{
"label":"type1-c",
"removed":null,
"dataid":null
},
{
"label":"type1-d",
"removed":null,
"dataid":null
}
]
},
{
"val":"type3",
"removed":"N",
"id":124,
"label":"type3-label1"
},
{
"val":"type4",
"removed":"N",
"id":126,
"label":"type4-label1"
},
{
"val":"type3",
"removed":null,
"id":128,
"label":"new"
}
]
result = [
{
"val":"type1new",
"removed":"N",
"id":1,
"data":[
{
"label":"type1new",
"removed":"N",
"dataid":16
},
{
"label":"type1-b",
"removed":"Y",
"dataid":26
},
{
"label":"type1-c",
"removed":null,
"dataid":null
},
{
"label":"type1-d",
"removed":null,
"dataid":null
}
]
},
{
"val":"type2",
"removed":"Y",
"data":[
{
"label":"type2-a",
"removed":"N",
"dataid":12
},
{
"label":"type2-b",
"removed":"N",
"dataid":34
}
]
},
{
"val":"type3",
"removed":"N",
"id":124,
"label":"type3-label1"
},
{
"val":"type4",
"removed":"N",
"id":126,
"label":"type4-label1"
},
{
"val":"type4",
"removed":"Y",
"id":128,
"label":"type4-label2"
},
{
"val":"type4",
"removed":null,
"id":null,
"label":"type4-label3"
},
{
"val":"type3",
"removed":null,
"id":128,
"label":"new"
}
]
---updated question above---