Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Structs . Map

This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Structs . Map

The keys of a Map can be arbitrary values.

var map = new Map([
   [ 1, 'one' ],
   [ 2, 'two' ],
   [ 3, 'three' ]
]);

Constructor:

new Map(elements)

Parameters:

name type description
elements Array.<*>

An optional array of key-value pairs to populate this Map with.

Since: 3.0.0
Source: src/structs/Map.js (Line 18)

Members

entries: Object.<string, *>
Focus
Focus

Description:

The entries in this Map.

Type:
Object.<string, *>
Default: {}
Since: 3.0.0
Source: src/structs/Map.js (Line 47)
Focus
Focus
size: number
Focus
Focus

Description:

The number of key / value pairs in this Map.

Type:
number
Default: 0
Since: 3.0.0
Source: src/structs/Map.js (Line 59)
Focus
Focus

Methods

clear()
Focus
Focus

Description:

Delete all entries from this Map.

Returns:
Description:

This Map object.

Examples:
Since: 3.0.0
Source: src/structs/Map.js (Line 191)
Focus
Focus
contains(value)
Focus
Focus

Description:

Returns true if the value exists within this Map. Otherwise, returns false.

Parameters:

name type description
value *

The value to search for.

Returns:
Description:

true if the value is found, otherwise false.

Type:
  • boolean
Examples:
Since: 3.0.0
Source: src/structs/Map.js (Line 304)
Focus
Focus
delete(key)
Focus
Focus

Description:

Delete the specified element from this Map.

Parameters:

name type description
key string

The key of the element to delete from this Map.

Returns:
Description:

This Map object.

Examples:
Since: 3.0.0
Source: src/structs/Map.js (Line 167)
Focus
Focus
dump()
Focus
Focus

Description:

Dumps the contents of this Map to the console via console.group.

Examples:
Since: 3.0.0
Source: src/structs/Map.js (Line 252)
Focus
Focus
each(callback)
Focus
Focus

Description:

Iterates through all entries in this Map, passing each one to the given callback.

If the callback returns false, the iteration will break.

Parameters:

name type description
callback EachMapCallback

The callback which will receive the keys and entries held in this Map.

Returns:
Description:

This Map object.

Examples:
Since: 3.0.0
Source: src/structs/Map.js (Line 274)
Focus
Focus
get(key)
Focus
Focus

Description:

Returns the value associated to the key, or undefined if there is none.

Parameters:

name type description
key string

The key of the element to return from the Map object.

Returns:
Description:

The element associated with the specified key or undefined if the key can't be found in this Map object.

Type:
  • *
Examples:
Since: 3.0.0
Source: src/structs/Map.js (Line 106)
Focus
Focus
getArray()
Focus
Focus

Description:

Returns an Array of all the values stored in this Map.

Returns:
Description:

An array of the values stored in this Map.

Type:
  • Array.<*>
Examples:
Since: 3.0.0
Source: src/structs/Map.js (Line 127)
Focus
Focus
has(key)
Focus
Focus

Description:

Returns a boolean indicating whether an element with the specified key exists or not.

Parameters:

name type description
key string

The key of the element to test for presence of in this Map.

Returns:
Description:

Returns true if an element with the specified key exists in this Map, otherwise false.

Type:
  • boolean
Examples:
Since: 3.0.0
Source: src/structs/Map.js (Line 150)
Focus
Focus
keys()
Focus
Focus

Description:

Returns all entries keys in this Map.

Returns:
Description:

Array containing entries' keys.

Type:
  • Array.
Examples:
Since: 3.0.0
Source: src/structs/Map.js (Line 214)
Focus
Focus
merge(map, [override])
Focus
Focus

Description:

Merges all new keys from the given Map into this one. If it encounters a key that already exists it will be skipped unless override is set to true.

Parameters:

name type arguments Default description
map Phaser.Structs.Map

The Map to merge in to this Map.

override boolean <optional> false

Set to true to replace values in this Map with those from the source map, or false to skip them.

Returns:
Description:

This Map object.

Examples:
Since: 3.0.0
Source: src/structs/Map.js (Line 331)
Focus
Focus
set(key, value)
Focus
Focus

Description:

Adds an element with a specified key and value to this Map. If the key already exists, the value will be replaced.

Parameters:

name type description
key string

The key of the element to be added to this Map.

value *

The value of the element to be added to this Map.

Returns:
Description:

This Map object.

Examples:
Since: 3.0.0
Source: src/structs/Map.js (Line 78)
Focus
Focus
values()
Focus
Focus

Description:

Returns an Array of all entries.

Returns:
Description:

An Array of entries.

Type:
  • Array.<*>
Examples:
Since: 3.0.0
Source: src/structs/Map.js (Line 229)
Focus
Focus