openharmony 鸿蒙 arkts-apis-arkts-collections-ConcatArray

2026-08-25 浏览 (1)

Interface (ConcatArray)

An array-like object that can be concatenated. This API extends ISendable.

NOTE

  • The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.

  • This module can be imported only to ArkTS files (with the file name extension .ets).

This section uses the following to identify the use of generics:

Modules to Import

import { collections } from '@kit.ArkTS';

Properties

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Utils.Lang

NameTypeRead OnlyOptionalDescription
lengthnumberYesNoNumber of elements in a ConcatArray.

[index: number]

readonly [index: number]: T

Returns the element at a given index in this ConcatArray.

System capability: SystemCapability.Utils.Lang

Parameters

NameTypeMandatoryDescription
indexnumberYesIndex of the element. The index starts from zero. The element at the specified index cannot be modified.

Return value

TypeDescription
TElement in the ConcatArray.

Error codes

For details about the error codes, see Universal Error Codes and Utils Error Codes.

IDError Message
401Parameter error. Illegal index.
10200001The value of index is out of range.

Example

let concatArray : collections.ConcatArray<number> = new collections.Array<number>(1, 2, 4);
console.info("Element at index 1: ", concatArray[1]);

join

join(separator?: string): string

Concatenates all elements in this array into a string, with a given separator.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Utils.Lang

Parameters

NameTypeMandatoryDescription
separatorstringNoSeparator to be used. If no value is passed in, a comma (,) is used as the separator.

Return value

TypeDescription
stringString obtained. If the array is empty, an empty string is returned.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Invalid separator.

Example

let concatArray : collections.ConcatArray<string> = new collections.Array<string>('a', 'b', 'c');
let joinedString = concatArray.join('-'); // "a-b-c" is returned.

slice

slice(start?: number, end?: number): ConcatArray<T>

Selects a range of elements in this array to create an array.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.Utils.Lang

Parameters

NameTypeMandatoryDescription
startnumberNoStart index of the range. If a negative number is passed in, it refers to the index of start + array.length. The default value is 0.
endnumberNoEnd index of the range (exclusive). If a negative number is passed in, it refers to the index of end + array.length. The default value is the length of the ArkTS array.

Return value

TypeDescription
ConcatArray<T>New array containing the selected elements.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Invalid `start` or `end` parameters.

Example

let concatArray : collections.ConcatArray<number> = new collections.Array<number>(1, 2, 3, 4, 5);
let slicedArray = concatArray.slice (1, 3); // [2, 3] is returned. The original array remains unchanged.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 arkts-apis-arkts-collections-Float32Array

openharmony 鸿蒙 arkts-apis-arkts-collections-ArrayBuffer

openharmony 鸿蒙 js-apis-lightweightset

openharmony 鸿蒙 errorcode-source-obfuscation

openharmony 鸿蒙 arkts-apis-arkts-utils-ASON

openharmony 鸿蒙 arkts-apis-arkts-collections-Uint8ClampedArray

openharmony 鸿蒙 errorcode-tsc

openharmony 鸿蒙 js-apis-deque

openharmony 鸿蒙 arkts-apis-arkts-collections-BitVector

openharmony 鸿蒙 js-apis-worker

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/fFtFajBo