Skip to main content
Skip table of contents

buildMap() Operation

Builds a map from an array.

Syntax

anArray.buildMap("aKeyName")

Semantics

Builds a map from an array. The operation returns a value of type Map.

Substitutables

anArray

Can be any variable or object attribute having the type Array and having array elements of complex type.

aKeyName

Name of the key attribute of the complex type in double quotes.

Examples

Input: an array of articles

JSON
{ "articles": [
    {"name": "AF-1200", "category": "Adapter", "serviceInterval": 52},
    {"name": "CD-2024", "category": "Connector", "serviceInterval": 208},
    {"name": "RC-0002", "category": "Adapter", "serviceInterval": 104}
]}
CODE
create hashMap;
set hashMap = articles.buildMap("name");

Result:

JSON
{
  "hashMap": {
    "AF-1200": {
      "category": "Adapter",
      "serviceInterval": 52
    },
    "CD-2024": {
      "category": "Connector",
      "serviceInterval": 208
    },
    "RC-0002" {
      "category": "Adapter",
      "serviceInterval": 104
    }
  }
}

buildMap() is a convenient method, if you need a map indexing an array.

Searching for items using a map key (name in the example above) is much faster than performing a select on the array. You should use a map if you need to search an array more than a couple of times.

Related Content

Related Pages:

  • Map Operations
    A hash map implements an associative array. You can build a map from an array, set and get map values and entries, and remove map values.

JavaScript errors detected

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

If this problem persists, please contact our support.