> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**ArrayList** is a linear data structure that is implemented based on arrays. **ArrayList** can dynamically adjust the capacity based on project requirements. It increases the capacity by 50% each time.
...
...
@@ -42,7 +41,7 @@ A constructor used to create an **ArrayList** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -77,7 +76,7 @@ Adds an element at the end of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -113,12 +112,12 @@ Inserts an element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The insert method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
...
...
@@ -151,7 +150,7 @@ Checks whether this container has the specified element.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -188,7 +187,7 @@ Obtains the index of the first occurrence of the specified element in this conta
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -230,7 +229,7 @@ Obtains the index of the last occurrence of the specified element in this contai
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -272,12 +271,12 @@ Removes an element with the specified position from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeByIndex method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
...
...
@@ -313,7 +312,7 @@ Removes the first occurrence of the specified element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -347,12 +346,12 @@ Removes from this container all of the elements within a range, including the el
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeByRange method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of fromIndex or toIndex is out of range. |
**Example**
...
...
@@ -391,7 +390,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -426,7 +425,7 @@ Uses a callback to traverse the elements in this container and obtain their posi
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callbackFn | function | Yes| Callback invoked to traverse the elements in the container.|
| callbackFn | function | Yes| Callback invoked for the replacement.|
| thisArg | Object | No| Value to use when the callback is invoked.|
callbackfn
...
...
@@ -439,7 +438,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -481,7 +480,7 @@ comparator
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -523,12 +522,12 @@ Obtains elements within a range in this container, including the element at the
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The subArrayList method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of fromIndex or toIndex is out of range. |
**Example**
...
...
@@ -553,7 +552,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -587,7 +586,7 @@ Clones this container and returns a copy. The modification to the copy does not
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -620,7 +619,7 @@ Obtains the capacity of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -653,7 +652,7 @@ Converts this container into an array.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -686,7 +685,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -719,7 +718,7 @@ Increases the capacity of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -747,7 +746,7 @@ Trims the capacity of this container to its current length.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -780,7 +779,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Double-ended queue (deque) is a sequence container implemented based on the queue data structure that follows the principles of First In First Out (FIFO) and Last In First Out (LIFO). It allows insertion and removal of elements at both the ends. **Deque** can dynamically adjust the capacity based on project requirements. It doubles the capacity each time. **Deque** differs from **[Queue](js-apis-queue.md)** and **[Vector](js-apis-vector.md)** mainly in the following aspects:
...
...
@@ -41,7 +40,7 @@ A constructor used to create a **Deque** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -69,7 +68,7 @@ Inserts an element at the front of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -104,7 +103,7 @@ Inserts an element at the end of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -145,7 +144,7 @@ Checks whether this container has the specified element.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -172,11 +171,11 @@ Removes the first element of this container.
| Type| Description|
| -------- | -------- |
| T | Element removed.|
| T | First element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -206,11 +205,11 @@ Removes the last element of this container.
| Type| Description|
| -------- | -------- |
| T | Element removed.|
| T | Last element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -254,7 +253,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -289,7 +288,7 @@ Obtains the first element of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -322,7 +321,7 @@ Obtains the last element of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -355,7 +354,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**HashMap** is a map implemented based on the array, linked list, and red-black tree. It provides efficient data query, insertion, and removal. The elements in a **HashMap** instance are mappings of key-value pairs. Each key must be unique and have only one value.
...
...
@@ -43,7 +42,7 @@ A constructor used to create a **HashMap** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -72,7 +71,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -108,7 +107,7 @@ Checks whether this container contains the specified key.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -146,7 +145,7 @@ Checks whether this container contains the specified value.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -184,7 +183,7 @@ Obtains the value of the specified key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -216,7 +215,7 @@ Adds all elements in a **HashMap** instance to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -256,7 +255,7 @@ Adds an element to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -292,7 +291,7 @@ Removes an element with the specified key from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -318,7 +317,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -350,7 +349,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -387,7 +386,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -431,7 +430,7 @@ Replaces an element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -470,7 +469,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -504,7 +503,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -542,14 +541,13 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The Symbol.iterator method cannot be bound. |
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**HashSet** is implemented based on [HashMap](js-apis-hashmap.md). In **HashSet**, only the **value** object is processed.
...
...
@@ -51,7 +50,7 @@ A constructor used to create a **HashSet** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -80,7 +79,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -116,7 +115,7 @@ Checks whether this container contains the specified element.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -154,7 +153,7 @@ Adds an element to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -190,7 +189,7 @@ Removes an element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -216,7 +215,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -248,7 +247,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -293,7 +292,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -326,7 +325,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -364,7 +363,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**LightWeightMap** stores key-value (KV) pairs. Each key must be unique and have only one value.
**LightWeightMap** is based on generics and uses a lightweight structure. Keys in the map are searched using hash values, which are stored in an array.
**LightWeightMap** is based on generics and uses a lightweight structure. Its default initial capacity is 8, and it has the capacity doubled in each expansion.
The keys in such a set are searched using hash values, which are stored in an array.
Compared with **[HashMap](js-apis-hashmap.md)**, which can also store KV pairs, **LightWeightMap** occupies less memory.
...
...
@@ -44,7 +45,7 @@ A constructor used to create a **LightWeightMap** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -73,7 +74,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -109,7 +110,7 @@ Checks whether this container contains all elements of the specified **LightWeig
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -149,7 +150,7 @@ Checks whether this container contains the specified key.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -159,10 +160,8 @@ For details about the error codes, see [containers Error Codes](../errorcodes/er
```ts
letlightWeightMap=newLightWeightMap();
letresult=lightWeightMap.hasKey;
lightWeightMap.hasKey("squirrel");
lightWeightMap.set("squirrel",123);
letresult1=lightWeightMap.hasKey("squirrel");
letresult=lightWeightMap.hasKey("squirrel");
```
...
...
@@ -188,7 +187,7 @@ Checks whether this container contains the specified value.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -214,7 +213,7 @@ Increases the capacity of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -256,7 +255,7 @@ Obtains the value of the specified key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -294,7 +293,7 @@ Obtains the index of the first occurrence of an element with the specified key i
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -332,7 +331,7 @@ Obtains the index of the first occurrence of an element with the specified value
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -370,12 +369,12 @@ Obtains the key of an element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getKeyAt method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
...
...
@@ -403,7 +402,7 @@ Adds all elements in a **LightWeightMap** instance to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -416,7 +415,7 @@ let lightWeightMap = new LightWeightMap();
lightWeightMap.set("squirrel",123);
lightWeightMap.set("sparrow",356);
letmap=newLightWeightMap();
lightWeightMap.setAll(map);
map.setAll(lightWeightMap);// Add all elements in lightWeightMap to the map.
```
...
...
@@ -442,7 +441,7 @@ Adds an element to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -478,7 +477,7 @@ Removes an element with the specified key from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -516,7 +515,7 @@ Removes an element at the specified position from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -555,12 +554,12 @@ Sets a value for an element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The setValueAt method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
...
...
@@ -594,12 +593,12 @@ Obtains the value of an element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getValueAt method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
...
...
@@ -621,7 +620,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -653,7 +652,7 @@ Obtains an iterator that contains all the keys in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -690,7 +689,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -735,7 +734,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -769,7 +768,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -800,13 +799,13 @@ Concatenates the elements in this container into a string and returns the string
**Return value**
| Type| Description|
| -------- | -------- |
| String | String obtained.|
| Type| Description|
| -------- | -------- |
| String | String obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -818,7 +817,7 @@ For details about the error codes, see [containers Error Codes](../errorcodes/er
letlightWeightMap=newLightWeightMap();
lightWeightMap.set("squirrel",123);
lightWeightMap.set("sparrow",356);
letiter=lightWeightMap.toString();
letresult=lightWeightMap.toString();
```
### [Symbol.iterator]
...
...
@@ -837,7 +836,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**LightWeightSet** stores a set of values, each of which must be unique.
...
...
@@ -44,7 +43,7 @@ A constructor used to create a **LightWeightSet** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -73,7 +72,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -108,7 +107,7 @@ Adds an element to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -138,7 +137,7 @@ Adds all elements in a **LightWeightSet** instance to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -178,7 +177,7 @@ Checks whether this container contains all elements of the specified **LightWeig
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -218,7 +217,7 @@ Checks whether this container has the specified key.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -246,7 +245,7 @@ Checks whether this container contains objects of the same type as the specified
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| obj | Object | Yes| Object to be used for comparison.|
| obj | Object | Yes| **LightWeightSet** instance to be used for comparison.|
**Return value**
...
...
@@ -256,7 +255,7 @@ Checks whether this container contains objects of the same type as the specified
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -289,12 +288,12 @@ Increases the capacity of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The increaseCapacityTo method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of minimumCapacity is out of range. |
**Example**
...
...
@@ -326,7 +325,7 @@ Obtains the position index of the element with the specified key in this contain
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -364,7 +363,7 @@ Removes an element of the specified key from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -402,7 +401,7 @@ Removes the element at the specified position from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -440,7 +439,7 @@ Obtains the value of the element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -466,7 +465,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -496,14 +495,6 @@ Obtains a string that contains all elements in this container.
| -------- | -------- |
| String | String obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The toString method cannot be bound. |
**Example**
```ts
...
...
@@ -530,7 +521,7 @@ Obtains an array that contains all objects in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -562,7 +553,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -607,7 +598,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -641,7 +632,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -678,7 +669,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**LinkedList** is implemented based on the doubly linked list. Each node of the doubly linked list has references pointing to the previous element and the next element. When querying an element, the system traverses the list from the beginning or end. **LinkedList** offers efficient insertion and removal operations but supports low query efficiency. **LinkedList** allows null elements.
Unlike **[List](js-apis-list.md)**, which is a singly linked list, **LinkedList** is a doubly linked list that supports insertion and removal at both ends.
**LinkedList** is less efficient in data access than **[ArrayList](js-apis-arraylist.md)**.
**LinkedList** is more efficient in data insertion than **[ArrayList](js-apis-arraylist.md)**, but less efficient in data access.
**Recommended use case**: Use **LinkedList** for frequent insertion and removal operations.
...
...
@@ -42,7 +41,7 @@ A constructor used to create a **LinkedList** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -78,7 +77,7 @@ Adds an element at the end of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -113,7 +112,7 @@ Adds an element at the top of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -149,12 +148,12 @@ Inserts an element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The insert method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
...
...
@@ -187,7 +186,7 @@ Checks whether this container has the specified element.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -224,7 +223,7 @@ Obtains an element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -266,7 +265,7 @@ Obtains the index of the last occurrence of the specified element in this contai
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -308,7 +307,7 @@ Obtains the index of the first occurrence of the specified element in this conta
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -350,12 +349,12 @@ Removes an element at the specified position from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeByIndex method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
...
...
@@ -385,7 +384,7 @@ Removes the first element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -420,7 +419,7 @@ Removes the last element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -461,7 +460,7 @@ Removes the first occurrence of the specified element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -500,7 +499,7 @@ Removes the first occurrence of the specified element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -540,7 +539,7 @@ Removes the last occurrence of the specified element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -574,7 +573,7 @@ Clones this container and returns a copy. The modification to the copy does not
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -617,7 +616,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -646,7 +645,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -686,12 +685,12 @@ Replaces an element at the specified position in this container with a given ele
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The set method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
...
...
@@ -720,7 +719,7 @@ Converts this container into an array.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -752,7 +751,7 @@ Obtains the first element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -785,7 +784,7 @@ Obtains the last element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -818,7 +817,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**List** is implemented based on the singly linked list. Each node has a reference pointing to the next element. When querying an element, the system traverses the list from the beginning. **List** offers efficient insertion and removal operations but supports low query efficiency. **List** allows null elements.
...
...
@@ -26,7 +25,7 @@ import List from '@ohos.util.List';
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**PlainArray** stores key-value (KV) pairs. Each key must be unique, be of the number type, and have only one value.
...
...
@@ -21,6 +20,8 @@ This topic uses the following to identify the use of generics:
importPlainArrayfrom'@ohos.util.PlainArray';
```
## PlainArray
### Attributes
...
...
@@ -42,7 +43,7 @@ A constructor used to create a **PlainArray** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -71,7 +72,7 @@ Checks whether this container is empty.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -107,7 +108,7 @@ Checks whether this container contains the specified key.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -145,7 +146,7 @@ Obtains the value of the specified key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -183,7 +184,7 @@ Obtains the index of the first occurrence of an element with the specified key i
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -221,7 +222,7 @@ Obtains the index of the first occurrence of an element with the specified value
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -259,7 +260,7 @@ Obtains the key of the element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -284,24 +285,24 @@ Obtains the value of an element at the specified position in this container.
**Parameters**
| Name| Type | Mandatory| Description|
| -------- | -------- | -------- | -------- |
| index | number | Yes| Position index of the target element.|
| Name| Type | Mandatory| Description|
| -------- | -------- | -------- | -------- |
| index | number | Yes| Position index of the target element.|
**Return value**
| Type| Description|
| -------- | -------- |
| T | Returns the value of the element if obtained; returns **undefined** otherwise.|
| Type| Description|
| -------- | -------- |
| T | Returns the value of the element if obtained; returns **undefined** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getValueAt method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
...
...
@@ -328,7 +329,7 @@ Clones this container and returns a copy. The modification to the copy does not
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -361,7 +362,7 @@ Adds an element to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -397,7 +398,7 @@ Removes an element with the specified key from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -435,7 +436,7 @@ Removes an element at the specified position from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -474,12 +475,12 @@ Removes elements in a specified range from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeRangeFrom method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
...
...
@@ -508,12 +509,12 @@ Sets a value for an element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The setValueAt method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
...
...
@@ -541,7 +542,7 @@ Obtains a string that contains all elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -567,7 +568,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -607,7 +608,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -641,7 +642,7 @@ Obtains an iterator object that contains key-value pairs, where the key is of th
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**Queue** follows the principle of First In First Out (FIFO). It supports insertion of elements at the end and removal from the front of the queue. **Queue** is implemented based on the queue data structure.
...
...
@@ -41,7 +40,7 @@ A constructor used to create a **Queue** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -76,7 +75,7 @@ Adds an element at the end of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -110,7 +109,7 @@ Removes the first element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -144,7 +143,7 @@ Obtains the first element of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -187,7 +186,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -222,7 +221,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**Stack** is implemented based on the array data structure. It follows the principle Last Out First In (LOFI) and supports data insertion and removal at one end.
...
...
@@ -40,7 +39,7 @@ A constructor used to create a **Stack** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -75,7 +74,7 @@ Adds an element at the top of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -109,7 +108,7 @@ Removes the top element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -143,7 +142,7 @@ Obtains the top element of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -182,7 +181,7 @@ Obtains the index of the first occurrence of the specified element in this conta
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -225,7 +224,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -260,7 +259,7 @@ Checks whether this container is empty (contains no elements).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -293,7 +292,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**TreeMap** stores key-value (KV) pairs. Each key must be unique and have only one value.
...
...
@@ -49,7 +48,7 @@ A constructor used to create a **TreeMap** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -78,7 +77,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -114,7 +113,7 @@ Checks whether this container has the specified key.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -152,7 +151,7 @@ Checks whether this container has the specified value.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -190,7 +189,7 @@ Obtains the value of the specified key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -222,7 +221,7 @@ Obtains the first key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -254,7 +253,7 @@ Obtains the last key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -282,11 +281,11 @@ Adds all elements in a **TreeMap** instance to this container.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| map | TreeMap<K,V> | Yes| **TreeMap**instance whose elements are to be added to the current container.|
| map | TreeMap<K,V> | Yes| **TreeMap**object to be added to the container.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -299,7 +298,11 @@ let treeMap = new TreeMap();
treeMap.set("squirrel",123);
treeMap.set("sparrow",356);
letmap=newTreeMap();
treeMap.setAll(map);
map.set("demo",12);
map.setAll(treeMap);// Add all elements in the treeMap to the map.
map.forEach((value,key)=>{
console.log("test"+value,key);// Print result: 12 demo, 356 sparrow, and 123 squirrel
})
```
...
...
@@ -326,7 +329,7 @@ Adds an element to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -362,7 +365,7 @@ Removes the element with the specified key from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -400,7 +403,7 @@ Obtains the key that is placed in front of the input key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -439,7 +442,7 @@ Obtains the key that is placed next to the input key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -478,7 +481,7 @@ Replaces an element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -503,7 +506,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -535,7 +538,7 @@ Obtains an iterator that contains all the keys in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -572,7 +575,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -617,7 +620,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -651,7 +654,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -688,7 +691,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**TreeSet** is implemented based on **[TreeMap](js-apis-treemap.md)**. In **TreeSet**, only **value** objects are processed. **TreeSet** can be used to store values, each of which must be unique.
...
...
@@ -46,7 +45,7 @@ A constructor used to create a **TreeSet** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -75,7 +74,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -111,7 +110,7 @@ Checks whether this container has the specified value.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -143,7 +142,7 @@ Obtains the value of the first element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -175,7 +174,7 @@ Obtains the value of the last element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -213,7 +212,7 @@ Adds an element to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -249,7 +248,7 @@ Removes the element with the specified key from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -287,7 +286,7 @@ Obtains the value that is placed in front of the input key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -326,7 +325,7 @@ Obtains the value that is placed next to the input key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -359,7 +358,7 @@ Removes the first element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -391,7 +390,7 @@ Removes the last element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -417,7 +416,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -449,7 +448,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -494,7 +493,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -528,7 +527,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
...
...
@@ -566,7 +565,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| protocol | string | Yes| Yes| Protocol in a URL.|
| search | string | Yes| Yes| Serialized query string in a URL.|
| searchParams | URLSearchParams | Yes| No| **URLSearchParams** object allowing access to the query parameters in a URL.|
| URLParams | URLParams | Yes| No| **URLParams** object allowing access to the query parameters in a URL.|
| searchParams<sup>(deprecated)</sup> | [URLSearchParams](#urlsearchparamsdeprecated) | Yes| No| **URLSearchParams** object allowing access to the query parameters in a URL.<br>- **NOTE**: This attribute is supported since API version 7 and is deprecated since API version 9. You are advised to use params<sup>9+</sup> instead.|
| params<sup>9+</sup> | [URLParams](#urlparams9) | Yes| No| **URLParams** object allowing access to the query parameters in a URL.|
| username | string | Yes| Yes| Username in a URL.|
### constructor<sup>(deprecated)</sup>
constructor(url: string, base?: string | URL)
Creates a URL.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [parseURL<sup>9+</sup>](#parseurl9) instead.
The **util** module provides common utility functions, such as **TextEncoder** and **TextDecoder** for string encoding and decoding, **RationalNumber** for rational number operations, **LruBuffer** for buffer management, **Scope** for range determination, **Base64** for Base64 encoding and decoding, and **Types** for checks of built-in object types.
...
...
@@ -41,38 +41,6 @@ let res = util.format("%s", "hello world!");
console.log(res);
```
## util.printf<sup>(deprecated)</sup>
printf(format: string, ...args: Object[]): string
Formats the specified values and inserts them into the string by replacing the wildcard in the string.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [util.format<sup>9+</sup>](#utilformat9) instead.
| ...args | Object[] | No| Values to format. The formatted values will be replaced the wildcard in the string.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | String containing the formatted values.|
**Example**
```js
letres=util.printf("%s","hello world!");
console.log(res);
```
## util.errnoToString<sup>9+</sup>
errnoToString(errno: number): string
...
...
@@ -96,43 +64,11 @@ Obtains detailed information about a system error code.
**Example**
```js
leterrnum=10;// 10 is a system error code.
leterrnum=-1;// -1 is a system error code.
letresult=util.errnoToString(errnum);
console.log("result = "+result);
```
## util.getErrorString<sup>(deprecated)</sup>
getErrorString(errno: number): string
Obtains detailed information about a system error code.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [util.errnoToString<sup>9+</sup>](#utilerrnotostring9) instead.
Formats the specified values and inserts them into the string by replacing the wildcard in the string.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [util.format<sup>9+</sup>](#utilformat9) instead.
| ...args | Object[] | No| Values to format. The formatted values will be replaced the wildcard in the string.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | String containing the formatted values.|
**Example**
```js
letres=util.printf("%s","hello world!");
console.log(res);
```
## util.getErrorString<sup>(deprecated)</sup>
getErrorString(errno: number): string
Obtains detailed information about a system error code.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [util.errnoToString<sup>9+</sup>](#utilerrnotostring9) instead.
A constructor used to create a **TextDecoder** object.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
| stream | boolean | No| Whether to allow data blocks in subsequent **decode()**. If data is processed in blocks, set this parameter to **true**. If this is the last data block to process or data is not divided into blocks, set this parameter to **false**. The default value is **false**.|
| stream | boolean | No| Whether to allow data blocks in subsequent **decodeWithStream()**. If data is processed in blocks, set this parameter to **true**. If this is the last data block to process or data is not divided into blocks, set this parameter to **false**. The default value is **false**.|
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [decodeWithStream<sup>9+</sup>](#decodewithstream9) instead.
| stream | boolean | No| Whether to allow data blocks in subsequent **decodeWithStream()**. If data is processed in blocks, set this parameter to **true**. If this is the last data block to process or data is not divided into blocks, set this parameter to **false**. The default value is **false**.|
| stream | boolean | No| Whether to allow data blocks in subsequent **decode()**. If data is processed in blocks, set this parameter to **true**. If this is the last data block to process or data is not divided into blocks, set this parameter to **false**. The default value is **false**.|
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [encodeInto<sup>9+</sup>](#encodeinto9) instead.
@@ -597,7 +588,7 @@ let that = new util.TextEncoder()
letbuffer=newArrayBuffer(4)
letdest=newUint8Array(buffer)
letresult=newObject()
result=that.encodeInto('abcd',dest)
result=that.encodeIntoUint8Array('abcd',dest)
```
### encodeInto<sup>(deprecated)</sup>
...
...
@@ -634,6 +625,38 @@ Stores the UTF-8 encoded text.
result=that.encodeInto('abcd',dest)
```
### encode<sup>(deprecated)</sup>
encode(input?: string): Uint8Array
Encodes the input content.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [encodeInto<sup>9+</sup>](#encodeinto9) instead.
A constructor used to create a **RationalNumber** object.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
| another | RationalNumber | Yes| Object used to compare with this **RationalNumber** object.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Returns **0** if the two objects are equal; returns **1** if the given object is less than this object; return **-1** if the given object is greater than this object.|
static getCommonDivisor(number1: number,number2: number): number
Obtains the greatest common divisor of two specified integers.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCommonFactor<sup>9+</sup>](#getcommonfactor9) instead.
A constructor used to create a **RationalNumber** object.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
| another | RationalNumber | Yes| Object used to compare with this **RationalNumber** object.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Returns **0** if the two objects are equal; returns **1** if the given object is less than this object; return **-1** if the given object is greater than this object.|
static getCommonDivisor(number1: number,number2: number): number
Obtains the greatest common divisor of two specified integers.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCommonFactor<sup>9+</sup>](#getcommonfactor9) instead.
A constructor used to create a **LruBuffer** instance. The default capacity of the buffer is 64.
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | -------------- |
| other | [ScopeComparable](#scopecomparable8) | Yes | The other value to be compared with the current value.|
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
Changes the **LruBuffer** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown.
| Type| Description|
| -------- | -------- |
| number | The value type is a number.|
| [ScopeComparable](#scopecomparable8) | The value type is ScopeComparable.|
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [updateCapacity<sup>9+</sup>](#updatecapacity9) instead.
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCapacity<sup>9+</sup>](#getcapacity9) instead.
Obtains the intersection of this **Scope** and the given **Scope**.
Obtains the number of return values for **createDefault()**.
getUpper(): ScopeType
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCreateCount<sup>9+</sup>](#getcreatecount9) instead.
Obtains the number of times that the queried values are mismatched.
getLower(): ScopeType
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getMissCount<sup>9+</sup>](#getmisscount9) instead.
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getRemovalCount<sup>9+</sup>](#getremovalcount9) instead.
Obtains the union set of this **Scope** and the given lower and upper limits.
Obtains the number of times that the queried values are matched.
expand(range: ScopeHelper): ScopeHelper
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getMatchCount<sup>9+</sup>](#getmatchcount9) instead.
Obtains the union set of this **Scope** and the given **Scope**.
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getPutCount<sup>9+</sup>](#getputcount9) instead.
Obtains the union set of this **Scope** and the given value.
| value | [ScopeType](#scopetype8) | Yes | Value specified.|
**Return value**
| Type| Description|
| -------- | -------- |
| V | Returns the existing value if the key already exists; returns the value added otherwise. If the key or value is null, an exception will be thrown. |
| [ScopeType](#scopetype8) | Returns **lowerObj** if the specified value is less than the lower limit; returns **upperObj** if the specified value is greater than the upper limit; returns the specified value if it is within this **Scope**.|
| src | Uint8Array \| string | Yes | Uint8Array or string to decode.|
**Return value**
| Type| Description|
| -------- | -------- |
| V \| undefined | Returns an **Optional** object containing the removed key-value pair if the key exists in the buffer; returns an empty **Optional** object otherwise. If the key is null, an exception will be thrown.|
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [afterRemoval<sup>9+</sup>](#afterremoval9) instead.
| isEvict | boolean | Yes| Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.|
| key | K | Yes| Key removed.|
| value | V | Yes| Value removed.|
| newValue | V | Yes| New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.|
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [createDefault<sup>9+</sup>](#createdefault9) instead.
Obtains a two-dimensional array in key-value pairs.
isAnyArrayBuffer(value: Object): boolean
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Symbol.iterator<sup>9+</sup>](#symboliterator9) instead.
Checks whether the input value is of the **ArrayBuffer** type.
Defines the type of values in a **Scope** object. The value type can be **ScopeComparable** or **number**.
The values of the **ScopeComparable** type are used to implement the **compareTo** method. Therefore, ensure that the input parameters are comparable.
```js
interfaceScopeComparable{
compareTo(other:ScopeComparable):boolean;
}
typeScopeType=ScopeComparable|number;
```
Create a class to implement the **compareTo** method. In the subsequent sample code, **Temperature** is used as an example of the [ScopeType](#scopetype8) object.
Example
```js
classTemperature{
constructor(value){
// If TS is used for development, add the following code:
Checks whether the input value is of the **ArrayBufferView** type.
A constructor used to create a **ScopeHelper** object with the specified upper and lower limits.
**ArrayBufferView** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.
| [ScopeType](#scopetype8) | Returns **lowerObj** if the specified value is less than the lower limit; returns **upperObj** if the specified value is greater than the upper limit; returns the specified value if it is within this **Scope**.|
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a generator function; returns **false** otherwise.|
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper<sup>9+</sup>](#scopehelper9) instead.
A constructor used to create a **Scope** object with the specified upper and lower limits.
### isGeneratorObject<sup>8+</sup>
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
isGeneratorObject(value: Object): boolean
Checks whether the input value is a generator object.
@@ -2947,259 +2915,255 @@ Limits a value to this **Scope**.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
| value | Object | Yes| Object to check.|
**Return value**
| Type| Description|
| -------- | -------- |
| [ScopeType](#scopetype8) | Returns **lowerObj** if the specified value is less than the lower limit; returns **upperObj** if the specified value is greater than the upper limit; returns the specified value if it is within this **Scope**.|
| boolean | Returns **true** if the input value is of the **Set** type; returns **false** otherwise.|
**Example**
```js
lettempLower=newTemperature(30);
lettempUpper=newTemperature(40);
lettempMiDF=newTemperature(35);
letrange=newutil.Scope(tempLower,tempUpper);
letresult=range.clamp(tempMiDF);
letthat=newutil.types();
letresult=that.isSet(newSet());
```
## Base64Helper<sup>9+</sup>
### constructor<sup>9+</sup>
### isSetIterator<sup>8+</sup>
constructor()
isSetIterator(value: Object): boolean
A constructor used to create a **Base64Helper** instance.
Checks whether the input value is of the **SetIterator** type.
| boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.|
**Example**
```js
letthat=newutil.Base64Helper();
letarray=newUint8Array([115,49,51]);
letresult=that.encodeToStringSync(array);
letthat=newutil.types();
constsymbols=Symbol('foo');
letresult=that.isSymbolObject(Object(symbols));
```
### decodeSync<sup>9+</sup>
### isTypedArray<sup>8+</sup>
decodeSync(src: Uint8Array | string): Uint8Array
isTypedArray(value: Object): boolean
Decodes the input content.
Checks whether the input value is of the **TypedArray** type.
**TypedArray** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint16Array**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.
| Promise<Uint8Array> | Uint8Array obtained after asynchronous decoding.|
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.|
**Example**
```js
letthat=newutil.Base64Helper();
letarray=newUint8Array([99,122,69,122]);
letrarray=newUint8Array([115,49,51]);
that.decode(array).then(val=>{
for(vari=0;i<rarray.length;i++){
console.log(val[i].toString())
}
})
letthat=newutil.types();
letresult=that.isUint16Array(newUint16Array([]));
```
## Base64<sup>(deprecated)</sup>
### isUint32Array<sup>8+</sup>
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper<sup>9+</sup>](#base64helper9) instead.
isUint32Array(value: Object): boolean
### constructor<sup>(deprecated)</sup>
Checks whether the input value is of the **Uint32Array** type.
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
| boolean | Returns **true** if the input value is of the **Uint32Array** type; returns **false** otherwise.|
**Example**
```js
letbase64=newutil.Base64();
letthat=newutil.types();
letresult=that.isUint32Array(newUint32Array([]));
```
### encodeSync<sup>(deprecated)</sup>
encodeSync(src: Uint8Array): Uint8Array
### isWeakMap<sup>8+</sup>
Encodes the input content.
isWeakMap(value: Object): boolean
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeSync<sup>9+</sup>](#encodesync9) instead.
Checks whether the input value is of the **WeakMap** type.
@@ -3207,31 +3171,27 @@ Encodes the input content.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode.|
| value | Object | Yes| Object to check.|
**Return value**
| Type| Description|
| -------- | -------- |
| Uint8Array | Uint8Array encoded.|
| boolean | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise.|
**Example**
```js
letthat=newutil.Base64();
letarray=newUint8Array([115,49,51]);
letresult=that.encodeSync(array);
letthat=newutil.types();
letresult=that.isWeakMap(newWeakMap());
```
### encodeToStringSync<sup>(deprecated)</sup>
encodeToStringSync(src: Uint8Array): string
### isWeakSet<sup>8+</sup>
Encodes the input content.
isWeakSet(value: Object): boolean
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeToStringSync<sup>9+</sup>](#encodetostringsync9) instead.
Checks whether the input value is of the **WeakSet** type.
@@ -3239,31 +3199,27 @@ Encodes the input content.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode.|
| value | Object | Yes| Object to check.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | String encoded from the Uint8Array.|
| boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.|
**Example**
```js
letthat=newutil.Base64();
letarray=newUint8Array([115,49,51]);
letresult=that.encodeToStringSync(array);
letthat=newutil.types();
letresult=that.isWeakSet(newWeakSet());
```
### decodeSync<sup>(deprecated)</sup>
decodeSync(src: Uint8Array | string): Uint8Array
### isBigInt64Array<sup>8+</sup>
Decodes the input content.
isBigInt64Array(value: Object): boolean
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [decodeSync<sup>9+</sup>](#decodesync9) instead.
Checks whether the input value is of the **BigInt64Array** type.
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeToString<sup>9+</sup>](#encodetostring9) instead.
Checks whether the input value is a module namespace object.
| length | number | Yes| No| Total number of values in this buffer.|
**Example**
```js
lettype=newutil.types();
letpro=newutil.LruBuffer();
pro.put(2,10);
pro.put(1,8);
letresult=pro.length;
```
### constructor<sup>(deprecated)</sup>
### isAnyArrayBuffer<sup>8+</sup>
constructor(capacity?: number)
isAnyArrayBuffer(value: Object): boolean
A constructor used to create a **LruBuffer** instance. The default capacity of the buffer is 64.
Checks whether the input value is of the **ArrayBuffer** type.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
Checks whether the input value is of the **ArrayBufferView** type.
Changes the **LruBuffer** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown.
**ArrayBufferView** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [updateCapacity<sup>9+</sup>](#updatecapacity9) instead.
| boolean | Returns **true** if the input value is of the **arguments** type; returns **false** otherwise.|
| string | String representation of this **LruBuffer** object.|
**Example**
```js
letthat=newutil.types();
functionfoo(){
varresult=that.isArgumentsObject(arguments);
}
letf=foo();
letpro=newutil.LruBuffer();
pro.put(2,10);
pro.get(2);
pro.remove(20);
letresult=pro.toString();
```
### getCapacity<sup>(deprecated)</sup>
### isArrayBuffer<sup>8+</sup>
getCapacity(): number
isArrayBuffer(value: Object): boolean
Obtains the capacity of this buffer.
Checks whether the input value is of the **ArrayBuffer** type.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCapacity<sup>9+</sup>](#getcapacity9) instead.
Obtains the number of return values for **createDefault()**.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCreateCount<sup>9+</sup>](#getcreatecount9) instead.
Obtains the number of times that the queried values are mismatched.
Checks whether the input value is of the **Boolean** type.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getMissCount<sup>9+</sup>](#getmisscount9) instead.
| boolean | Returns **true** if the input value is of the **Boolean** type; returns **false** otherwise.|
| number | Number of times that the queried values are mismatched.|
**Example**
```js
letthat=newutil.types();
letresult=that.isBooleanObject(newBoolean(true));
letpro=newutil.LruBuffer();
pro.put(2,10);
pro.get(2);
letresult=pro.getMissCount();
```
### getRemovalCount<sup>(deprecated)</sup>
### isBoxedPrimitive<sup>8+</sup>
getRemovalCount(): number
isBoxedPrimitive(value: Object): boolean
Obtains the number of removals from this buffer.
Checks whether the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getRemovalCount<sup>9+</sup>](#getremovalcount9) instead.
Obtains the number of times that the queried values are matched.
Checks whether the input value is of the **DataView** type.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getMatchCount<sup>9+</sup>](#getmatchcount9) instead.
| boolean | Returns **true** if the input value is of the **DataView** type; returns **false** otherwise.|
| number | Number of times that the queried values are matched.|
**Example**
```js
letthat=newutil.types();
constab=newArrayBuffer(20);
letresult=that.isDataView(newDataView(ab));
letpro=newutil.LruBuffer();
pro.put(2,10);
pro.get(2);
letresult=pro.getMatchCount();
```
### getPutCount<sup>(deprecated)</sup>
### isDate<sup>8+</sup>
getPutCount(): number
isDate(value: Object): boolean
Obtains the number of additions to this buffer.
Checks whether the input value is of the **Date** type.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getPutCount<sup>9+</sup>](#getputcount9) instead.
@@ -3740,85 +3680,84 @@ Checks whether the input value is of the **Float64Array** type.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
| key | K | Yes| Key of the key-value pair to add.|
| value | V | Yes| Value of the key-value pair to add.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Float64Array** type; returns **false** otherwise.|
| V | Returns the existing value if the key already exists; returns the value added otherwise. If the key or value is null, an exception will be thrown. |
**Example**
```js
letthat=newutil.types();
letresult=that.isFloat64Array(newFloat64Array());
letpro=newutil.LruBuffer();
letresult=pro.put(2,10);
```
### values<sup>(deprecated)</sup>
### isGeneratorFunction<sup>8+</sup>
values(): V[]
isGeneratorFunction(value: Object): boolean
Obtains all values in this buffer, listed from the most to the least recently accessed.
Checks whether the input value is a generator function.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [values<sup>9+</sup>](#values9) instead.
@@ -3826,27 +3765,30 @@ Checks whether the input value is of the **Int8Array** type.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
| key | K | Yes| Key to remove.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int8Array** type; returns **false** otherwise.|
| V \| undefined | Returns an **Optional** object containing the removed key-value pair if the key exists in the buffer; returns an empty **Optional** object otherwise. If the key is null, an exception will be thrown.|
Performs subsequent operations after a value is removed.
Checks whether the input value is of the **Int16Array** type.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [afterRemoval<sup>9+</sup>](#afterremoval9) instead.
@@ -3854,27 +3796,43 @@ Checks whether the input value is of the **Int16Array** type.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int16Array** type; returns **false** otherwise.|
| isEvict | boolean | Yes| Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.|
| key | K | Yes| Key removed.|
| value | V | Yes| Value removed.|
| newValue | V | Yes| New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.|
@@ -3882,27 +3840,31 @@ Checks whether the input value is of the **Int32Array** type.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
| key | K | Yes| Key to check.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int32Array** type; returns **false** otherwise.|
| boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.|
**Example**
```js
letthat=newutil.types();
letresult=that.isInt32Array(newInt32Array([]));
letpro=newutil.LruBuffer();
pro.put(2,10);
letresult=pro.contains(20);
```
### createDefault<sup>(deprecated)</sup>
### isMap<sup>8+</sup>
createDefault(key: K): V
isMap(value: Object): boolean
Creates a value if the value of the specified key is not available.
Checks whether the input value is of the **Map** type.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [createDefault<sup>9+</sup>](#createdefault9) instead.
Obtains a two-dimensional array in key-value pairs.
Checks whether the input value is of the **Error** type.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Symbol.iterator<sup>9+</sup>](#symboliterator9) instead.
| boolean | Returns **true** if the input value is of the **Error** type; returns **false** otherwise.|
| [K, V] | Two-dimensional array in key-value pairs.|
**Example**
```js
letthat=newutil.types();
letresult=that.isNativeError(newTypeError());
letpro=newutil.LruBuffer();
pro.put(2,10);
letresult=pro[Symbol.iterator]();
```
## Scope<sup>(deprecated)</sup>
### isNumberObject<sup>8+</sup>
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper<sup>9+</sup>](#scopehelper9) instead.
A constructor used to create a **Scope** object with the specified upper and lower limits.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
Checks whether the input value is a number object.
@@ -4195,30 +4177,35 @@ Checks whether the input value is a symbol object.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.|
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given **Scope**.|
**Example**
```js
letthat=newutil.types();
constsymbols=Symbol('foo');
letresult=that.isSymbolObject(Object(symbols));
lettempLower=newTemperature(30);
lettempUpper=newTemperature(40);
lettempMiDF=newTemperature(35);
lettempMidS=newTemperature(39);
letrange=newutil.Scope(tempLower,tempUpper);
letrangeFir=newutil.Scope(tempMiDF,tempMidS);
letresult=range.expand(rangeFir);
```
### expand<sup>(deprecated)</sup>
### isTypedArray<sup>8+</sup>
isTypedArray(value: Object): boolean
expand(value: ScopeType): Scope
Checks whether the input value is of the **TypedArray** type.
Obtains the union set of this **Scope** and the given value.
**TypedArray** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint16Array**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand<sup>9+</sup>](#expand9) instead.
@@ -4310,55 +4318,58 @@ Checks whether the input value is of the **Uint16Array** type.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.|
| [ScopeType](#scopetype8) | Returns **lowerObj** if the specified value is less than the lower limit; returns **upperObj** if the specified value is greater than the upper limit; returns the specified value if it is within this **Scope**.|
**Example**
```js
letthat=newutil.types();
letresult=that.isUint16Array(newUint16Array([]));
lettempLower=newTemperature(30);
lettempUpper=newTemperature(40);
lettempMiDF=newTemperature(35);
letrange=newutil.Scope(tempLower,tempUpper);
letresult=range.clamp(tempMiDF);
```
### isUint32Array<sup>8+</sup>
isUint32Array(value: Object): boolean
## Base64<sup>(deprecated)</sup>
Checks whether the input value is of the **Uint32Array** type.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper<sup>9+</sup>](#base64helper9) instead.
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint32Array** type; returns **false** otherwise.|
Checks whether the input value is of the **WeakMap** type.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeSync<sup>9+</sup>](#encodesync9) instead.
@@ -4366,27 +4377,31 @@ Checks whether the input value is of the **WeakMap** type.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
| src | Uint8Array | Yes| Uint8Array to encode.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise.|
| Uint8Array | Uint8Array encoded.|
**Example**
```js
letthat=newutil.types();
letresult=that.isWeakMap(newWeakMap());
letthat=newutil.Base64();
letarray=newUint8Array([115,49,51]);
letresult=that.encodeSync(array);
```
### encodeToStringSync<sup>(deprecated)</sup>
### isWeakSet<sup>8+</sup>
encodeToStringSync(src: Uint8Array): string
isWeakSet(value: Object): boolean
Encodes the input content.
Checks whether the input value is of the **WeakSet** type.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeToStringSync<sup>9+</sup>](#encodetostringsync9) instead.
@@ -4394,27 +4409,31 @@ Checks whether the input value is of the **WeakSet** type.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
| src | Uint8Array | Yes| Uint8Array to encode.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.|
| string | String encoded from the Uint8Array.|
**Example**
```js
letthat=newutil.types();
letresult=that.isWeakSet(newWeakSet());
letthat=newutil.Base64();
letarray=newUint8Array([115,49,51]);
letresult=that.encodeToStringSync(array);
```
### decodeSync<sup>(deprecated)</sup>
### isBigInt64Array<sup>8+</sup>
decodeSync(src: Uint8Array | string): Uint8Array
isBigInt64Array(value: Object): boolean
Decodes the input content.
Checks whether the input value is of the **BigInt64Array** type.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [decodeSync<sup>9+</sup>](#decodesync9) instead.
Checks whether the input value is a module namespace object.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeToString<sup>9+</sup>](#encodetostring9) instead.
The worker thread is an independent thread running in parallel with the main thread. The thread that creates the worker thread is referred to as the host thread. The URL file passed in during worker creation is executed in the worker thread. The worker thread can process time-consuming operations, but cannot directly operate the UI.
With the **Worker** module, you can provide a multithreading environment for an application, so that the application can perform a time-consuming operation in a background thread. This greatly prevents a computing-intensive or high-latency task from blocking the running of the main thread. A **Worker** instance will not be proactively destroyed once it is created. It consumes resources to keep running. Therefore, you should call the API to terminate it in a timely manner.
The **Context** object of the worker thread is different from that of the main thread. The worker thread does not support UI operations.
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...
...
@@ -40,13 +42,13 @@ Provides options that can be set for the **Worker** instance to create.
## ThreadWorker<sup>9+</sup>
Before using the following APIs, you must create a **Worker** instance. The **Worker** class inherits from [WorkerEventTarget](#workereventtarget9).
Before using the following APIs, you must create a **ThreadWorker** instance. The **ThreadWorker** class inherits from [WorkerEventTarget](#workereventtarget9).
Sends a message to the worker thread. The data type of the message must be sequenceable. For details about the sequenceable data types, see [More Information](#more-information).
@@ -154,6 +201,15 @@ Sends a message to the worker thread. The data type of the message must be seque
| message | Object | Yes | Message to be sent to the worker thread. |
| options | [PostMessageOptions](#postmessageoptions) | No | **ArrayBuffer** instances that can be transferred. The **transferList** array cannot contain **null**.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
@@ -181,6 +236,15 @@ Adds an event listener for the worker thread. This API provides the same functio
| type | string | Yes | Type of the event to listen for. |
| listener | [WorkerEventListener](#workereventlistener9) | Yes| Callback to invoke when an event of the specified type occurs. Callback to invoke when an event of the specified type occurs.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| 10200005 | The invoked API is not supported in workers. |
**Example**
```js
...
...
@@ -206,6 +270,15 @@ Adds an event listener for the worker thread and removes the event listener afte
| type | string | Yes | Type of the event to listen for. |
| listener | [WorkerEventListener](#workereventlistener9) | Yes| Callback to invoke when an event of the specified type occurs. Callback to invoke when an event of the specified type occurs.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| 10200005 | The invoked API is not supported in workers. |
**Example**
```js
...
...
@@ -231,6 +304,15 @@ Removes an event listener for the worker thread. This API provides the same func
| type | string | Yes | Type of the event for which the event listener is to be removed. |
| listener | [WorkerEventListener](#workereventlistener9) | No| Callback to invoke when an event of the specified type occurs. Callback of the event listener to remove.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| type | string | Yes | Type of the event for which the event listener is to be removed. |
| callback | [WorkerEventListener](#workereventlistener9) | No| Callback to invoke when an event of the specified type occurs. Callback of the event listener to remove.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| type | string | Yes | Type of the event for which the event listener is to be removed. |
| callback | [WorkerEventListener](#workereventlistener9) | No| Callback to invoke when an event of the specified type occurs. Callback of the event listener to remove.|
| callback | [WorkerEventListener](#workereventlistener9) | No| Callback to invoke when an event of the specified type occurs. |
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ------------------------------- |
| 10200004 | Worker instance is not running. |
**Example**
...
...
@@ -434,6 +740,14 @@ Dispatches the event defined for the worker thread.
| ------- | ------------------------------- |
| boolean | Returns **true** if the event is dispatched successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
Implements communication between the worker thread and the host thread. The **postMessage** API is used to send messages to the host thread, and the **close** API is used to terminate the worker thread. The **ThreadWorkerGlobalScope** class inherits from [GlobalScope<sup>9+</sup>](#globalscope9).
@@ -515,6 +884,15 @@ Sends a message to the host thread from the worker thread.
| message | Object | Yes | Message to be sent to the worker thread. |
| options | [PostMessageOptions](#postmessageoptions) | No | **ArrayBuffer** instances that can be transferred. The **transferList** array cannot contain **null**.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
Defines the event handler to be called when the worker thread receives a message sent by the host thread through **postMessage**. The event handler is executed in the worker thread.
...
...
@@ -578,7 +964,16 @@ Defines the event handler to be called when the worker thread receives a message
Defines the event handler to be called when the worker thread receives a message that cannot be deserialized. The event handler is executed in the worker thread.
...
...
@@ -612,7 +1007,16 @@ Defines the event handler to be called when the worker thread receives a message
Sends a message to the worker thread. The data type of the message must be sequenceable. For details about the sequenceable data types, see [More Information](#more-information).
...
...
@@ -830,9 +1244,9 @@ Sends a message to the worker thread. The data type of the message must be seque
| message | Object | Yes | Message to be sent to the worker thread. |
| options | [PostMessageOptions](#postmessageoptions) | No | **ArrayBuffer** instances that can be transferred. The **transferList** array cannot contain **null**.|
| transfer | ArrayBuffer[] | Yes | **ArrayBuffer** instances that can be transferred.|
**Example**
...
...
@@ -845,6 +1259,32 @@ var buffer = new ArrayBuffer(8);
Sends a message to the worker thread. The data type of the message must be sequenceable. For details about the sequenceable data types, see [More Information](#more-information).
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [ThreadWorker.postMessage<sup>9+</sup>](#postmessage9-1) instead.
| message | Object | Yes | Message to be sent to the worker thread. |
| options | [PostMessageOptions](#postmessageoptions) | No | **ArrayBuffer** instances that can be transferred. The **transferList** array cannot contain **null**.|
@@ -1219,6 +1659,44 @@ Implements communication between the worker thread and the host thread. The **po
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [ThreadWorkerGlobalScope<sup>9+</sup>](#threadworkerglobalscope9) instead.
Defines the event handler to be called when the worker thread receives a message sent by the host thread through **postMessage**. The event handler is executed in the worker thread.
...
...
@@ -1304,7 +1781,7 @@ Defines the event handler to be called when the worker thread receives a message
Defines the event handler to be called when the worker thread receives a message that cannot be deserialized. The event handler is executed in the worker thread.
...
...
@@ -1340,7 +1817,7 @@ Defines the event handler to be called when the worker thread receives a message
// parentPort.postMessage(func1); A serialization error occurs when passing func1.
// parentPort.postMessage(obj1); A serialization error occurs when passing obj1.
parentPort.postMessage(obj2);// No serialization error occurs when passing obj2.
// workerPort.postMessage(func1); A serialization error occurs when passing func1.
// workerPort.postMessage(obj1); A serialization error occurs when passing obj1.
workerPort.postMessage(obj2);// No serialization error occurs when passing obj2.
}
parentPort.onmessageerror=function(e){
workerPort.onmessageerror=function(e){
console.log("worker.js onmessageerror");
}
parentPort.onerror=function(e){
workerPort.onerror=function(e){
console.log("worker.js onerror");
}
```
...
...
@@ -1571,6 +2048,7 @@ Each actor concurrently processes tasks of the main thread. For each actor, ther
- Since API version 9, if a **Worker** instance in a non-running state (such as destroyed or being destroyed) calls an API, a business error is thrown.
- Creating and terminating worker threads consume performance. Therefore, you are advised to manage available workers and reuse them.
- Do not use both **new worker.Worker** and **new worker.ThreadWorker** to create a **Worker** project. Otherwise, **Worker** functions abnormally. Since API version 9, you are advised to use [new worker.ThreadWorker](#constructor9). In API version 8 and earlier versions, you are advised to use [new worker.Worker](#constructordeprecated).
- When creating a **Worker** project, do not import any UI construction method (such as .ets file) to the worker thread file (for example, **worker.ts** used in this document). Otherwise, the worker module becomes invalid. To check whether any UI construction method has been imported, decompress the generated HAP file, find **worker.js** in the directory where the worker thread is created, and search for the keyword **View** globally. If the keyword exists, a UI construction method has been packaged in **worker.js**. If this is your case, change the directory level of **src** in the statement **import "xxx" from src** in the worker thread file.
// key indicates the event type, and value indicates the parsing depth. You can learn the specific parsed event based on EVENTTYPE. In this example, key: value means:
// 0(START_DOCUMENT):0 (START_DOCUMENT is being parsed, and the depth is 0), 2(START_TAG):1 (START_TAG is being parsed, and the depth is 1), 10(WHITESPACE):1 (WHITESPACE is being parsed, and the depth is 1), 2(START_TAG):2 (START_TAG is being parsed, and the depth is 2), ...
```
### getLineNumber
...
...
@@ -429,6 +601,38 @@ Obtains the current line number, starting from 1.
| inFile | string | Yes | Path of the folder or file to zip. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).|
| inFile | string | Yes | Path of the folder or file to zip. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the zipped file. The file name extension is .zip. |
| options | [Options](#options) | Yes | Optional parameters for the zip operation. |
...
...
@@ -39,6 +39,7 @@ Zips a file. This API uses a promise to return the result.
```typescript
// Zip a file.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
importzlibfrom'@ohos.zlib';
letinFile='/xxx/xxx';
letoutFile='/xxx/xxx.zip';
...
...
@@ -89,7 +91,7 @@ Unzips a file. This API uses a promise to return the result.
| inFile | string | Yes | Path of the folder or file to unzip. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).|
| inFile | string | Yes | Path of the file to unzip. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the unzipped file. |
| options | [Options](#options) | Yes | Optional parameters for the unzip operation. |
...
...
@@ -103,6 +105,7 @@ Unzips a file. This API uses a promise to return the result.
```typescript
// Unzip a file.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
importzlibfrom'@ohos.zlib';
letinFile='/xx/xxx.zip';
letoutFile='/xxx';
...
...
@@ -131,7 +134,7 @@ Compresses a file. This API uses an asynchronous callback to return the result.
| inFile | string | Yes | Path of the folder or file to compress. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).|
| inFile | string | Yes | Path of the folder or file to compress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the compressed file. |
| AsyncCallback<**void**> | callback | No | Callback used to return the result. If the operation is successful, **null** is returned; otherwise, a specific error code is returned. |
...
...
@@ -141,14 +144,14 @@ Compresses a file. This API uses an asynchronous callback to return the result.
For details about the error codes, see [zlib Error Codes](../errorcodes/errorcode-zlib.md).
| 900002 | The Input destination file is invalid. |
| 900001 | The input source file is invalid. |
| 900002 | The input destination file is invalid. |
**Example**
```typescript
// Compress a file.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through context.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
importzlibfrom'@ohos.zlib';
letinFile='/xxx/filename.xxx';
letoutFile='/xxx/xxx.zip';
...
...
@@ -179,7 +182,7 @@ Compresses a file. This API uses a promise to return the result.
| inFile | string | Yes | Path of the folder or file to compress. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).|
| inFile | string | Yes | Path of the folder or file to compress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the compressed file. |
| 900002 | The Input destination file is invalid. |
| 900001 | The input source file is invalid. |
| 900002 | The input destination file is invalid. |
```typescript
// Compress a file.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through context.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
importzlibfrom'@ohos.zlib';
letinFile='/xxx/filename.xxx';
letoutFile='/xxx/xxx.zip';
...
...
@@ -229,7 +232,7 @@ Decompresses a file. This API uses an asynchronous callback to return the result
| inFile | string | Yes | Path of the file to decompress. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).|
| inFile | string | Yes | Path of the file to decompress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the decompressed file. |
| AsyncCallback<**void**> | callback | No | Callback used to return the result. If the operation is successful, **null** is returned; otherwise, a specific error code is returned. |
...
...
@@ -240,14 +243,14 @@ For details about the error codes, see [zlib Error Codes](../errorcodes/errorcod
| 900002 | The Input destination file is invalid. |
| 900001 | The input source file is invalid. |
| 900002 | The input destination file is invalid. |
**Example**
```typescript
// Decompress a file.
// The path used in the code must be the application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through context.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
| inFile | string | Yes | Path of the file to decompress. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).|
| inFile | string | Yes | Path of the file to decompress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the decompressed file. |
| 900002 | The Input destination file is invalid. |
| 900001 | The input source file is invalid. |
| 900002 | The input destination file is invalid. |
```typescript
// Decompress a file.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through context.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.