# Arrays & Maps

### Arrays

An ArrayUtil is a dynamic array-like data structure that can store elements of any type. Conceptually, it behaves like an array but with additional functionalities and flexibility.

#### Methods

* `ArrayUtils.empty(<T>) -> Array<T>`: Returns new empty array of type `T`.
* `add(value: T)`: Adds a value to the array.
* `set(index: Integer, value: T)`: Sets the value of the element at the given `index`.
* `remove(index: Integer)`: Removes the value in the array at index.
* `size() -> Integer`: returns the size of the array.
* `clear()`: Clears the array removing all it's values.

#### Usage

```typescript
var array = ArrayUtils.empty(String);

array.add("N");
array.add("B");
array.add("C");

if (array.get(0) == "N") {
    array.set(0, "A");
}

array.add("D");
array.remove(3);

array.clear();
if (array.size() == 0) {
    return true;
}
```

***

### Maps

A map  represented as `HashMap<Object, Object>`, is a collection that associates unique keys with corresponding values, facilitating efficient retrieval and modification of data based on key references.

{% hint style="info" %}
HashMaps are especially useful for defining a row in [SuiteTable](/5.4/scripting/types-and-objects/objects/suitetable.md)
{% endhint %}

#### Syntax

> A `{` followed by zero or more sets of `key : value` pairs separated by `,` and ending with `}`, e.g. `{ "one" : 1, "two" : 2, "three" : 3, "more": "many more" }`
>
> This syntax creates a `HashMap<Object,Object>`.
>
> Empty map literal can be specified as `{:}`

#### Methods

* `create(); Map`

Creates an empty map and returns it.

* `add(Map<String, Object> map, String key, Object value): void`

adds a key-value pair to map. Returns nothing

* `size(); Integer`

Returns number of key-value pairs in map.

* `isEmpty: Boolean`

Returns true of map is empty, otherwise returns false.

* `cotainsKey(Object key): Boolean`

Returns true if map contains specified key, otherwise returns false.

* `containsValue(Object value): Boolean`

Returns true if map contains specified value, otherwise returns false.

* `remove(String key): Object`

Removes key from Map and returns the remove value object.

* `keySet(); and values();`

Return the keys and values of the map, respectively.

#### Usage

<pre class="language-javascript"><code class="lang-javascript"><strong>var map = MapUtil.create();
</strong>
MapUtil.add(map, "name", "steve");
MapUtil.add(map, "age", 40);
MapUtil.add(map, "birthday", LocalDate.now());

map.values(); // returns 2023-11-22,steve,40
map.keySet(); // returns birthday,name,age
map.remove("age"); // remove, age from map and returns 40

return map; 
</code></pre>

Or you can define map Manually:

```javascript
var map = {
    "name": "steve",
    "age": 40,
    "birthday": LocalDate.now()
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.b2winsuite.com/5.4/scripting/types-and-objects/arrays-and-maps.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
