I have a JSON object that I'm only interested in one of the key "codes" and its values. I would like to run a loop to get those values for every region and country and city and store them in an array.
{
"region":{
"America":{
"countries":{
"US":{
"cities":{
"NY":{
"codes":["142","2243","312","4123","5132"]
},
"LA":{
"codes":["1465","2465","3453","4132","542"]
}
}
},
"CANADA":{
"cities":{
"TORNTO":{
"codes":["1465","2465","3453","4132","542"]
}
}
}
}
},
"ASIA":{
"countries":{
"India":{
"cities":{
"Delhi ":{
"codes":["142","2243","312","4123","5132"]
},
"Calcutta":{
"codes":["1465","2465","3453","4132","542"]
}
}
},
"CHINA":{
"cities":{
"HONKKON":{
"codes":["1465","2465","3453","4132","542"]
}
}
}
}
}
}
}
what I have done
getCodes(regions){
let ccode = [];
for (let key of Object.values(region)) {
for (let temp of Object.values(key)) {
for (let ctemp of Object.values(temp)) {
for (btemp of Object.values(ctemp)) {
for (let bbtemp of Object.values(btemp)) {
ccode.push(...bbtemp["code"])
}
}
}
}
}
}
However, all my interest is to collect the codes values in every single region and put them together in a list. any practical way?