I need help with manipulating a nested object that contains multiple keys, where each key includes a title and children. The children array consists of objects with their own title and children keys, forming a tree structure. How can I efficiently search for and replace one word or part of a title's value within this nested structure?
const object = {
id: 'uuid',
title: 'hello You',
type: number,
visibility: true,
children: [
{
id: 'uuid',
title: 'You don't have any comments...',
type: number,
visibility: true,
children: [{...}, {...}, ...],
key1: {...},
key2: [{...}]
},
{
id: 'uuid',
title: 'You your problem is not with json...',
type: number,
visibility: true,
children: [{...}, {...}, ...],
key1: {...},
key2: [{...}]
}
],
key1: {...},
key2: [{...}]
}
search you
and replace world
on title
output = {
id: 'uuid',
title: 'hello world',
type: number,
visibility: true,
children: [
{
id: 'uuid',
title: 'world don't have any comments...',
type: number,
visibility: true,
children: [{...}, {...}, ...],
key1: {...},
key2: [{...}]
},
{
id: 'uuid',
title: 'world your problem is not with json...',
type: number,
visibility: true,
children: [{...}, {...}, ...],
key1: {...},
key2: [{...}]
}
],
key1: {...},
key2: [{...}]
}