查找 OpenLayers 数组的索引
Find index of OpenLayers array
我很难找到这个特定 OpenLayers 数组的索引。
数组看起来像这样。
Array(7)
0: PinchRotate {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…},
revision_: 0, …}
1: PinchZoom {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…}, revision_:
0, …}
2: KeyboardPan {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…},
revision_: 0, …}
3: KeyboardZoom {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…},
revision_: 0, …}
4: MouseWheelZoom {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…},
revision_: 0, …}
5: DragBox {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…}, revision_:
0, …}
6: PointerInteraction {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…},
revision_: 0, …}
我正在尝试查找索引项 =“DragBox”的索引
我已经尝试过字符串和对象,即
let index = MapValues.map.interactions.array_.indexOf("DragBox");
let obj = DragBox
let index = MapValues.map.interactions.array_.indexOf(obj);
两者都返回了 -1...我真的很困惑如何用打字稿中的这个特定数组来做到这一点。
非常感谢任何帮助
要在数组中搜索特定类型的对象,可以使用
.findIndex(obj => obj instanceof DragBox)
我很难找到这个特定 OpenLayers 数组的索引。 数组看起来像这样。
Array(7)
0: PinchRotate {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…},
revision_: 0, …}
1: PinchZoom {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…}, revision_:
0, …}
2: KeyboardPan {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…},
revision_: 0, …}
3: KeyboardZoom {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…},
revision_: 0, …}
4: MouseWheelZoom {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…},
revision_: 0, …}
5: DragBox {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…}, revision_:
0, …}
6: PointerInteraction {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…},
revision_: 0, …}
我正在尝试查找索引项 =“DragBox”的索引
我已经尝试过字符串和对象,即
let index = MapValues.map.interactions.array_.indexOf("DragBox");
let obj = DragBox
let index = MapValues.map.interactions.array_.indexOf(obj);
两者都返回了 -1...我真的很困惑如何用打字稿中的这个特定数组来做到这一点。
非常感谢任何帮助
要在数组中搜索特定类型的对象,可以使用
.findIndex(obj => obj instanceof DragBox)