- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
长话短说,数组的长度取决于所选的城市,因此我无法使用索引选择元素,因为我不知道该元素的索引是什么。因此,我需要根据其属性之一的值来选择它。
就我而言,我想选择包含具有属性 types: ['locality', 'political']
的对象的元素。
示例结果。我没有包含前 7 个数组元素,因为它们不相关:
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"
如您所见,每个元素都有一个 types
属性,它是一个数组。我目前正在尝试使用 types: ['locality', 'political']
而不是索引来选择索引为 7 的元素。
遗憾的是我不知道如何做到这一点,所以我没有补充任何代码。
[
{
"address_components": [
{
"long_name": "19",
"short_name": "19",
"types": [
"street_number"
]
},
{
"long_name": "Clanbrassil Street Lower",
"short_name": "Clanbrassil Street Lower",
"types": [
"route"
]
},
{
"long_name": "Wood Quay",
"short_name": "Wood Quay",
"types": [
"neighborhood",
"political"
]
},
{
"long_name": "Dublin 8",
"short_name": "Dublin 8",
"types": [
"postal_town"
]
},
{
"long_name": "County Dublin",
"short_name": "County Dublin",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "Ireland",
"short_name": "IE",
"types": [
"country",
"political"
]
},
{
"long_name": "D08 X798",
"short_name": "D08 X798",
"types": [
"postal_code"
]
}
],
"formatted_address": "19 Clanbrassil Street Lower, Wood Quay, Dublin, D08 X798, Ireland",
"geometry": {
"location": {
"lat": 53.3349244,
"lng": -6.2740099
},
"location_type": "ROOFTOP",
"viewport": {
"northeast": {
"lat": 53.3362733802915,
"lng": -6.272660919708499
},
"southwest": {
"lat": 53.3335754197085,
"lng": -6.275358880291503
}
}
},
"place_id": "ChIJZckoE7wNZ0gRgHdbQYYvYTk",
"plus_code": {
"compound_code": "8PMG+X9 Dublin, County Dublin, Ireland",
"global_code": "9C5M8PMG+X9"
},
"types": [
"cafe",
"establishment",
"food",
"point_of_interest"
]
},
{
"address_components": [
{
"long_name": "21",
"short_name": "21",
"types": [
"street_number"
]
},
{
"long_name": "R137",
"short_name": "R137",
"types": [
"route"
]
},
{
"long_name": "Wood Quay",
"short_name": "Wood Quay",
"types": [
"neighborhood",
"political"
]
},
{
"long_name": "Dublin 8",
"short_name": "Dublin 8",
"types": [
"postal_town"
]
},
{
"long_name": "County Dublin",
"short_name": "County Dublin",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "Ireland",
"short_name": "IE",
"types": [
"country",
"political"
]
}
],
"formatted_address": "21 R137, Wood Quay, Dublin, Ireland",
"geometry": {
"location": {
"lat": 53.3348735,
"lng": -6.273865
},
"location_type": "ROOFTOP",
"viewport": {
"northeast": {
"lat": 53.3362224802915,
"lng": -6.272516019708497
},
"southwest": {
"lat": 53.3335245197085,
"lng": -6.275213980291502
}
}
},
"place_id": "ChIJYVO9ECIMZ0gR2bQrf0Ktmso",
"plus_code": {
"compound_code": "8PMG+WF Dublin, County Dublin, Ireland",
"global_code": "9C5M8PMG+WF"
},
"types": [
"street_address"
]
},
{
"address_components": [
{
"long_name": "18",
"short_name": "18",
"types": [
"street_number"
]
},
{
"long_name": "Clanbrassil Street Lower",
"short_name": "Clanbrassil Street Lower",
"types": [
"route"
]
},
{
"long_name": "Wood Quay",
"short_name": "Wood Quay",
"types": [
"neighborhood",
"political"
]
},
{
"long_name": "Dublin 8",
"short_name": "Dublin 8",
"types": [
"postal_town"
]
},
{
"long_name": "County Dublin",
"short_name": "County Dublin",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "Ireland",
"short_name": "IE",
"types": [
"country",
"political"
]
}
],
"formatted_address": "18 Clanbrassil Street Lower, Wood Quay, Dublin, Ireland",
"geometry": {
"location": {
"lat": 53.3349987,
"lng": -6.2739341
},
"location_type": "RANGE_INTERPOLATED",
"viewport": {
"northeast": {
"lat": 53.3363476802915,
"lng": -6.272585119708499
},
"southwest": {
"lat": 53.3336497197085,
"lng": -6.275283080291502
}
}
},
"place_id": "EiwxOCBDbGFuYnJhc3NpbCBTdHJlZXQgTG93ZXIsIER1YmxpbiwgSXJlbGFuZCIaEhgKFAoSCQexJhIiDGdIEUlWW2rVpRfqEBI",
"types": [
"street_address"
]
},
{
"address_components": [
{
"long_name": "Clanbrassil Street Lower",
"short_name": "R137",
"types": [
"route"
]
},
{
"long_name": "Merchants Quay",
"short_name": "Merchants Quay",
"types": [
"neighborhood",
"political"
]
},
{
"long_name": "Dublin 8",
"short_name": "Dublin 8",
"types": [
"postal_town"
]
},
{
"long_name": "County Dublin",
"short_name": "County Dublin",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "Ireland",
"short_name": "IE",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Clanbrassil Street Lower, Merchants Quay, Dublin, Ireland",
"geometry": {
"bounds": {
"northeast": {
"lat": 53.33516729999999,
"lng": -6.273907599999999
},
"southwest": {
"lat": 53.3345896,
"lng": -6.274462
}
},
"location": {
"lat": 53.3348778,
"lng": -6.274183000000001
},
"location_type": "GEOMETRIC_CENTER",
"viewport": {
"northeast": {
"lat": 53.33622743029149,
"lng": -6.272835819708497
},
"southwest": {
"lat": 53.33352946970849,
"lng": -6.275533780291502
}
}
},
"place_id": "ChIJzSxnESIMZ0gR8A77SK0ccBQ",
"types": [
"route"
]
},
{
"address_components": [
{
"long_name": "Wood Quay",
"short_name": "Wood Quay",
"types": [
"neighborhood",
"political"
]
},
{
"long_name": "Dublin 8",
"short_name": "Dublin 8",
"types": [
"postal_town"
]
},
{
"long_name": "County Dublin",
"short_name": "County Dublin",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "Ireland",
"short_name": "IE",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Wood Quay, Dublin, Ireland",
"geometry": {
"bounds": {
"northeast": {
"lat": 53.3454641,
"lng": -6.2680769
},
"southwest": {
"lat": 53.329641,
"lng": -6.275519999999999
}
},
"location": {
"lat": 53.33275459999999,
"lng": -6.2706881
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 53.3454641,
"lng": -6.2680769
},
"southwest": {
"lat": 53.329641,
"lng": -6.275519999999999
}
}
},
"place_id": "ChIJl78TlSEMZ0gRUHtT8SkTqVA",
"types": [
"neighborhood",
"political"
]
},
{
"address_components": [
{
"long_name": "Dublin 8",
"short_name": "Dublin 8",
"types": [
"postal_town"
]
},
{
"long_name": "County Dublin",
"short_name": "County Dublin",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "Ireland",
"short_name": "IE",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Dublin 8, Ireland",
"geometry": {
"bounds": {
"northeast": {
"lat": 53.37132399999999,
"lng": -6.2642699
},
"southwest": {
"lat": 53.325953,
"lng": -6.3563488
}
},
"location": {
"lat": 53.34785249999999,
"lng": -6.318115199999999
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 53.37132399999999,
"lng": -6.2642699
},
"southwest": {
"lat": 53.325953,
"lng": -6.3563488
}
}
},
"place_id": "ChIJLz14IT8MZ0gR2uKxYpAO0Bc",
"types": [
"postal_town"
]
},
{
"address_components": [
{
"long_name": "Dublin City",
"short_name": "Dublin City",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "County Dublin",
"short_name": "County Dublin",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "Ireland",
"short_name": "IE",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Dublin City, Co. Dublin, Ireland",
"geometry": {
"bounds": {
"northeast": {
"lat": 53.4111566,
"lng": -6.11309
},
"southwest": {
"lat": 53.2988569,
"lng": -6.387080600000001
}
},
"location": {
"lat": 53.3603142,
"lng": -6.315054200000001
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 53.4111566,
"lng": -6.11309
},
"southwest": {
"lat": 53.2988569,
"lng": -6.387080600000001
}
}
},
"place_id": "ChIJv2RI7foRZ0gRwAKA8azHAAM",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"address_components": [
{
"long_name": "Dublin",
"short_name": "Dublin",
"types": [
"locality",
"political"
]
},
{
"long_name": "County Dublin",
"short_name": "County Dublin",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "Ireland",
"short_name": "IE",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Dublin, Ireland",
"geometry": {
"bounds": {
"northeast": {
"lat": 53.42521010000001,
"lng": -6.0439235
},
"southwest": {
"lat": 53.22343009999999,
"lng": -6.4474847
}
},
"location": {
"lat": 53.3498053,
"lng": -6.2603097
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 53.42521010000001,
"lng": -6.0439235
},
"southwest": {
"lat": 53.22343009999999,
"lng": -6.4474847
}
}
},
"place_id": "ChIJL6wn6oAOZ0gRoHExl6nHAAo",
"types": [
"locality",
"political"
]
},
{
"address_components": [
{
"long_name": "County Dublin",
"short_name": "County Dublin",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "Ireland",
"short_name": "IE",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Co. Dublin, Ireland",
"geometry": {
"bounds": {
"northeast": {
"lat": 53.6347257,
"lng": -5.9962748
},
"southwest": {
"lat": 53.1781971,
"lng": -6.5468798
}
},
"location": {
"lat": 53.3302033,
"lng": -6.3105655
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 53.6347257,
"lng": -5.9962748
},
"southwest": {
"lat": 53.1781971,
"lng": -6.5468798
}
}
},
"place_id": "ChIJv2RI7foRZ0gRwAKA8azHABg",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"address_components": [
{
"long_name": "Ireland",
"short_name": "IE",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Ireland",
"geometry": {
"bounds": {
"northeast": {
"lat": 55.4602,
"lng": -5.668900100000001
},
"southwest": {
"lat": 51.3066,
"lng": -10.7666001
}
},
"location": {
"lat": 53.41291,
"lng": -8.24389
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 55.4602,
"lng": -5.668900100000001
},
"southwest": {
"lat": 51.3066,
"lng": -10.7666001
}
}
},
"place_id": "ChIJ-ydAXOS6WUgRCPTbzjQSfM8",
"types": [
"country",
"political"
]
}
]
最佳答案
您可以找到包含上述每种类型的元素:
array.find(it => ['locality', 'political'].every(type => it.types.includes(type)))
关于javascript - 我有一组根据所选城市长度不同的对象。如何选择持有具有某种属性的对象的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55210520/
来自 Java/C# 背景,我正在尝试实现一个空安全检查对象。以下代码尝试检查对象上是否确实存在颜色。如果有,我希望能够做一些事情(比如在形状上绘制颜色)。我希望能够将此颜色设置回 null (non
目前,我正在使用来自 Boost Vault 的类型安全枚举类: Which Typesafe Enum in C++ Are You Using? 我发现很难有一个父类指针来引用所有枚举类,因为 B
假设我设置了一个存储库。我希望有的用户可以推送,有的用户我想先过一遍推送的内容再批准。有条件推送之类的概念吗?待批准推送队列? 最佳答案 您本质上需要一个代码审查工具。 git 有一些,但最好的可能是
我使用 Windows 版 git bash 和 Beyond & Compare 作为我的差异工具(但同样的事情发生在任何外部差异工具上)。 我希望我的终端不要等待 difftool 退出以返回终端
这个问题在这里已经有了答案: SVN: Is there a way to mark a file as "do not commit"? (18 个回答) 8年前关闭。 在某些情况下,作为开发环境设
Jcombobox 可以保存 int 吗?因为我尝试了这个并收到错误。 int[] timeSched = new int[] {200,300,400,500}; JComboBox Jcombo1
最近,我开始为我的游戏制作 map 编辑器,遇到了一些问题,我已经解决了这些问题。我现在的问题是我有一个 JFrame (主界面)。在该 JFrame 中,我有一个 JScrollPane,其中包含我
ElementAdapter类 package com.example.sierendeelementeninbreda; import android.content.Context; import
我能以某种方式将 jquery 对象作为 javascript 对象的键吗? (编辑)..作为关键.. var $a = $("#a"); var $b = $("#b"); var c = {};
我分两步解码 jpeg。 检查边界,必要时确定比例。 在屏幕限制内解码。 public static Bitmap decodeSampledBitmapFromInputStream(InputSt
谁能告诉我为什么下面代码中 $mytextarea 的范围没有扩展到 getAnswerToo() 函数中? getAnswer() 之所以有效,是因为我明确选择了要更新的元素。但是,尝试使用全局“处
如果我有实现接口(interface) I 的类 A 并将它传递到需要接口(interface) I 的地方,例如传递给线程,将这会阻止 GC 对 A 类的实例进行垃圾回收?我想是的,但我该如何解决呢
我正在使用 Swift3 和 Xcode 8.3.3 我正在研究持有 UICollectionView 的 UITableViewCell。每个 CollectionView 单元格都需要执行 seg
我正在使用 CVMetalTextureCacheCreateTextureFromImage 从 CVImageBuffer(来自相机和播放器)创建一个 MTLTexture 以获得 CVMetal
我有三个类:HopBill、HopBillController 和 HopBillSheetController。 HopBill 创建一个包含 NSMutableArray 的对象。出于测试目的,我
一些 Powermock/Mockito 文章提到了使用 PowerMock.mockStaticPartial 方法 - 唯一的问题是我在任何地方都找不到它! 有谁知道它存在于哪个 Artifact
我有一个显示新闻条目详细信息的 ViewPager。您可以在 30 个条目之间来回滑动。这些条目中的每一个都是一个包含 ImageView 的 View 。此 ImageView 使用 Picasso
操作应尽量保持与原始输入类型相同的答案,因此如果持有者以 Double 开头,则结果也应该是 double。 如果输入包含不同数字类型的持有者,那么它应该自动加宽等。 应该有一种带有 getter 的
比如,如果我编写如下所示的代码: const int & const_value = 10; 与看起来像这样的代码相比,我有什么优势: int value = 10; 或 const int cons
我在 Windows XP(代码:Block,MinGW)和 Ubuntu(11.04,G++)上运行了以下两段代码 我无法运行以下代码 #include using namespace std;
我是一名优秀的程序员,十分优秀!