Reputation: 1592
****************UPDATED*********************************************************
I have an array under an array:
I want to remove an element from children array where type="tag" and name="style". children array is an array within the array of objects printed below.
My aim is also to keep the original array of objects intact.
I am using the following code but it is giving me undefined:
// ARRAY of Objects
const responseText = html.parse(businessResponseText);
console.log('responseText',responseText);
// Needs work ---- how do I transform this original object?
const transformedObject = {
...responseText,
children: responseText.map((children)=>{
children.children.filter(
el => el.type !== "tag" && el.name !== "style"
)
})
}
console.log('transformedobject',transformedObject);
this is the output I get: original vs transformed
Upvotes: 1
Views: 82
Reputation: 1939
const transformedList = styleFree.map(obj => ({
...obj,
children: obj.children.filter(
el => el.type !== "tag" && el.name !== "style"
)
})
Upvotes: 2
Reputation: 1018
Copy and paste the code snippet as it would be easy for others to try it. Make the world better place! ;)
stylefree = stylefree.map((children) => {
children.children = children.children.filter((nested)=>{
return (nested.type!="tag" && nested.name!="style");
});
return children;
});
Upvotes: 1