Search a string in JSON using Typescript. How can I search for a string in the below given JSON array? The JSON input array is given below.
let JSON_DATA: Object[] = [
{
id: "1",
name: 'cricket',
subNames: [
{
id: 2,
name: 'bat',
subNames: [
{
id: 3,
name: 'batsman',
subNames: [
{
id: 4,
subNames: 'left',
}
]
}
]
},
{
id: ,
name: 'ball',
subNames: [
{
id: 6,
subNames: 'red',
},
{
id: 7,
name: 'white',
}
]
}
]
},
{
id: 8,
name: 'football',
subNames: [
{
id: 9,
name: 'boot',
subNames: [
{
id: 10,
name: 'white',
}
]
}
]
},
]
I want to search a string in the above JSON object
For example, if a user types 'white' then it should search for the string 'white' in the whole JSON array and return the JSON object like below...
let JSON_DATA: Object[] = [
{
id: "1",
name: 'cricket',
subNames: [
{
id: ,
name: 'ball',
subNames: [
{
id: 7,
name: 'white',
}
]
}
]
},
{
id: 8,
name: 'football',
subNames: [
{
id: 9,
name: 'boot',
subNames: [
{
id: 10,
name: 'white',
}
]
}
]
},
]