Find index of OpenLayers array

81 views Asked by At

I'm having difficulty finding the index of this particular OpenLayers array. The array looks like this.

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, …}

I'm trying to find the index where the index item = "DragBox"

I've tried both a string and an object i.e.

let index =  MapValues.map.interactions.array_.indexOf("DragBox");

let obj = DragBox
let index =  MapValues.map.interactions.array_.indexOf(obj);

Both have returned -1...i'm really confused as to how to do this with this particular array in typescript.

Any help is greatly appreciated

1

There are 1 answers

0
Mike On BEST ANSWER

To search for an object of a particular type in an array use can use

.findIndex(obj => obj instanceof DragBox)