# Interface IMapIterator<K, T>

GoJS® Diagramming Components
version 3.0.13
by Northwoods Software®

This interface defines properties and methods for iterating over a Map; it provides the next predicate and the key and value read-only properties.

Iterating over Maps is very similar to an Iterator<IKeyValuePair>, but not exactly, because the type of the value property is T, not an IKeyValuePair.

Typical usage is:

     const it = aMap.iterator;
     while (it.next()) {
       const key = it.key;
       const val = it.value;
     }

`see`

Iterator

#### Type Parameters

- #### K

- #### T

#####
Index

### Methods

all
any
each
first
next
reset

### Properties

count
iterator
key
value

## Methods

### all

- all(pred: ((x: IKeyValuePair<K, T>) => boolean)): boolean

- This is true if all invocations of the given predicate on items in the collection are true.

  Call the given predicate on each item in the collection. As soon as a call returns false, this returns false. Otherwise this returns true. For an empty collection this returns true.

  This automatically reset's itself when it is called.

  #### Parameters

  - ##### pred: ((x: IKeyValuePair<K, T>) => boolean)

    This function must not have any side-effects.

    - - (x: IKeyValuePair<K, T>): boolean

      - #### Parameters

        - ##### x: IKeyValuePair<K, T>

        #### Returns boolean

  True if all predicate calls are true; false otherwise.

### any

- any(pred: ((x: IKeyValuePair<K, T>) => boolean)): boolean

- This is true if any invocation of the given predicate on items in the collection is true.

  Call the given predicate on each item in the collection. As soon as a call returns true, this returns true. Otherwise this returns false. For an empty collection this returns false.

  This automatically reset's itself when it is called.

  #### Parameters

  - ##### pred: ((x: IKeyValuePair<K, T>) => boolean)

    This function must not have any side-effects.

    - - (x: IKeyValuePair<K, T>): boolean

      - #### Parameters

        - ##### x: IKeyValuePair<K, T>

        #### Returns boolean

  True if any predicate call is true; false otherwise.

### each

- each(func: ((x: IKeyValuePair<K, T>) => void)): IMapIterator<K, T>

- Call the given function on each item in the collection.

  This automatically reset's itself when it is called.

  #### Parameters

  - ##### func: ((x: IKeyValuePair<K, T>) => void)

    This function must not modify the collection.

    - - (x: IKeyValuePair<K, T>): void

      - #### Parameters

        - ##### x: IKeyValuePair<K, T>

        #### Returns void

  #### Returns IMapIterator<K, T>

  this iterator itself

### first

- first(): IKeyValuePair<K, T>

- Advance if needed to the first item in the collection and return it, or return null if there is none. Returns a key/value pair, not a value.

  #### Returns IKeyValuePair<K, T>

### next

- next(): boolean

- Call this method to advance the iterator to the next item in the collection. This should be called before accessing any value.

  #### Returns boolean

  whether another item is available; when true the value of value will be that item.

### reset

- reset(): void

- Start this iterator all over again.

  #### Returns void

## Properties

### `Readonly` count
: number

This read-only property is the total number of items in the iterated collection.

### iterator
: IMapIterator<K, T>

Returns itself, which is convenient for code that expects an Iterable instead of an Iterator.

### `Readonly` key
: K

Gets the current key in the collection, assuming next has just returned true.

### `Readonly` value
: T

Gets the current value in the collection, assuming next has just returned true.

Copyright © 1998-2024 by Northwoods Software Corporation.