Hello everyone i have an object
const obj = {
a: {
uniqueId: 'u_a',
},
groupA: {
uniqueId: 'u_groupA',
nested: {
b: {
uniqueId: 'u_b',
},
c: {
uniqueId: 'u_c',
},
anotherGroup: {
uniqueId: 'u_anotherGroup',
nested: {
d: {
uniqueId: 'u_d',
},
e: {
uniqueId: 'u_e',
},
}
},
}
},
};
and i have an **array that holds the uniqueId values ** like this
[ 'u_a', 'u_b', 'u_c' ] and so on so
- What i want to do is loop through the array and extract the specific nodes -- for more understanding
- if the array is [ 'u_a' ] The result will be
const result = {
a: {
uniqueId: 'u_a',
},
};
- And If The Array is [ 'u_b' ] the result will be
const result = {
groupA: {
uniqueId: 'u_groupA',
nested: {
b: {
uniqueId: 'u_b',
},
}
}
};
- And If The array is [ 'u_a', 'u_b', 'u_d' ] The result will be:
const result = {
a: {
uniqueId: 'u_a',
},
groupA: {
uniqueId: 'u_groupA',
nested: {
b: {
uniqueId: 'u_b',
},
anotherGroup: {
uniqueId: 'u_anotherGroup',
nested: {
d: {
uniqueId: 'u_d',
},
}
},
}
},
};
and So on
How can i do that
- List of uniqueIDs
- Loop through them and search for each one inside the object
- extract the founded node only Not All Elements
Thanks in Advance.