kasim mohamed

kasim mohamed

  • 1.7k
  • 57
  • 6.9k

Filter the json object

Sep 5 2020 10:12 AM
const base = [
{id: 1,name: 'A1'}, {id: 11,name: 'A11'},
{id: 12,name: 'A2'}, {id: 111,name: 'A111'},
{id: 112,name: 'A112'}, {id: 121,name: 'A121'},
{id: 122,name: 'A122'},
{id: 2,name: 'A2'},{id: 3,name: 'A3'},{id: 4,name: 'A4'}
];
const tree = [
{id: 1, parent:0, level: 'L1'},
{id: 11, parent:1, level: 'L2'},
{id: 111, parent:11, level: 'L3'},
{id: 112, parent:11, level: 'L3'},
{id: 12, parent:1, level: 'L2'},
{id: 121, parent:12, level: 'L3'},
{id: 122, parent:12, level: 'L3'},
]
i have two object one is base another one is tree. if i pass the 'id=11' it has to remove the [id:11]'s level 'L2' and its top level 'L1' id from the base object and result the remaining values. the below result am expecting
const result = [
{id: 111,name: 'A111'},
{id: 112,name: 'A112'}, {id: 121,name: 'A121'},
{id: 122,name: 'A122'},
{id: 2,name: 'A2'},{id: 3,name: 'A3'},{id: 4,name: 'A4'}
];
how to achieve this?

Answers (10)