Currently i have below Array of Objects
obj = [
{
"id":28,
cities: [
{
cityTypes: "AA",
citySource: "sdsf"
},
{
cityTypes: "BB",
citySource: "sdsgf"
},
{
cityTypes: "CC",
citySource: "fgsdfgd"
}
]
},
{
"id":56,
cities: [
{
cityTypes: "DD",
citySource: "sdsf"
},
{
cityTypes: "EE",
citySource: "sdsgf"
},
{
cityTypes: "FF",
citySource: "fgsdfgd"
}
]
},
{
"id":89,
cities: [
{
cityTypes: "GG",
citySource: "sdsf"
},
{
cityTypes: "HH",
citySource: "sdsgf"
},
{
cityTypes: "II",
citySource: "fgsdfgd"
}
]
}
]
I need to search cityTypes of specific value is present in the whole Object.
For suppose, i need to search cityTypes = BB
If BB is present in the whole object, return true
If BB is not preset, return false.
This is what i have tried, which does not seem to work.
for(let k=0; k<obj.length; k++){
if(obj[k].cities){
let cityObj = obj[k].cities;
for(let city in cityObj){
city.cityTypes !== "BB" ? "true" : "false"
}
}
}
What is the proper way to achieive this?