I have the following data:
var data = {
someData : [
{
title: "something",
color: "red",
moreInfo : [
{
title: "something else",
color: "orange",
moreInfo : [
{
title: "something more",
color: "green",
moreInfo : [
{
title: "another title",
color: "yellow"
}
]
}
]
},
{
title: "blah blah",
color: "blue"
}
]
},
{
title: "something cool",
color: "black"
}
]
};
I want to run a function to return the object with the property that matches a certain value. Currently I have this:
var result = data.filter(obj => {
return obj.title === "something more";
});
I want the function to be able to iterate through every object and nested object and return the object with that value. So in this case I would like for it to return:
{
title: "something more",
color: "green",
moreInfo: [
{
title: "another title",
color: "yellow"
}
]
}
If someone could please help me with this. It seems simple enough but I have spent way too much time on this.Thank you!
somedata = []it should besomedata : []