Skip to main content
Skip table of contents

Using Maps in JavaScript

Like in Action Script (see section Map Operations), you can also use maps in JavaScript. You can build/create a map, add new elements to a map, retrieve and remove items from a map and get map entries. Maps can also be used as input/output parameters to a JavaScript operation.

The following tables shows some map task and their implementation with Action Script and JavaScript.

Task

Action Script / JavaScript

Additional Information

Creating a new map

create myMap;

let myMap = new Base_Components_Basic_Behavior_Map_Map();

Building a map from an array

set myMap = myArray.buildMap("name");

See buildMap() Operation in Map Context.

let myMap = new Base_Components_Basic_Behavior_Map_Map(myArray, "name");

Building a map from an array:

CODE
let header = new Base_Components_Basic_Behavior_Map_Entry();
entry1.name = 'key1';
entry1.value = 'value1';
 
let entry2 = new Base_Components_Basic_Behavior_Map_Entry();
entry2.name = 'key2';
entry2.value = 'value2';
 
let myArray = new Array();
myArray.push(entry1);
myArray.push(entry2);
 
let myMap = new Base_Components_Basic_Behavior_Map_Map(myArray, "name");

Retrieving an item from a map

set anObject = myMap.getMapValue("my key");

See getMapValue() Operation.

let value = myMap.getEntry('my key');

Getting map entries

set anArray = myMap.getMapEntries();

See getMapEntries() Operation.

let mapEntries = myMap.getEntries();
let entryValue = mapEntries[0].value;

Adding a new element to a map

set anObject = myMap.setMapValue("my key", "my value");

  • All simple types except Blob can be used as a key for the map.

  • All values are allowed, except arrays and anonymous objects.

See setMapValue() Operation.

myMap.setEntry('my key', 'my value');

Removing an item from a map

set deletedObject = myMap.removeMapValue("my key");

See removeMapValue() Operation.

let removed = myMap.removeEntry('my key');

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.