Is there a way to filter an array of objects to only include elements that have 'text' containing 'ild'?
For example, consider the following array:
public data: any[] = [
{
treeViewKey:0,
id: 1,
text: 'Root Node 1'
}, {
treeViewKey:1,
id: 2,
text: 'Root Node 2'
}, {
treeViewKey:1_0,
id: 3,
parentId: 2,
text: 'Child node of Root Node 2'
}, {
treeViewKey:1_1,
id: 4,
parentId: 2,
text: 'Child node of Root Node 2'
}, {
treeViewKey:1_2_0,
id: 5,
parentId: 4,
text: 'Child node of Root Node 2'
}
];
I want to extract the elements where 'text' contains 'ild'. How can this be done efficiently using javascript or typescript?
The desired output would be:
[
{
treeViewKey:1_0,
id: 3,
parentId: 2,
text: 'Child node of Root Node 2'
}, {
treeViewKey:1_1,
id: 4,
parentId: 2,
text: 'Child node of Root Node 2'
}, {
treeViewKey:1_2_0,
id: 5,
parentId: 4,
text: 'Child node of Root Node 2'
}
]