My dilemma arises from the fact that the length of an array depends on the selected city, making it impossible to select elements using an index. In this scenario, I need to devise a method to choose elements based on the value of one of their properties.
In particular, I am interested in selecting elements containing objects with the property types: ['locality', 'political']
.
For instance, consider the following results (excluding the first 7 array elements as they are irrelevant):
7:
address_components: (3) [{…}, {…}, {…}]
types: Array(2)
0: "locality"
1: "political"
8:
address_components: (2) [{…}, {…}]
types: Array(2)
0: "administrative_area_level_1"
1: "political"
Each element features a types
property represented as an array. My current aim is to identify the element at index 7 based on types: ['locality', 'political']
rather than its index.
Unfortunately, I haven't figured out how to achieve this yet, so I haven't written any code segments.
[
{
"address_components": [
...
],
"formatted_address": ...,
"geometry": {
...
},
"place_id": ...,
"plus_code": {
...
},
"types": [
...
]
},
...
]