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

2026-08-25 浏览 (1)

Class (ArrayBuffer)

Underlying data structure of the ArkTS TypedArray (Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Uint8ClampedArray, and Float32Array).

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).

Decorator: @Sendable

Modules to Import

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

Properties

System capability: SystemCapability.Utils.Lang

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

NameTypeRead OnlyOptionalDescription
byteLengthnumberYesNoNumber of bytes occupied by the buffer.

constructor

constructor(byteLength: number)

A constructor used to create an ArkTS ArrayBuffer of a given length.

System capability: SystemCapability.Utils.Lang

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

Parameters

NameTypeMandatoryDescription
byteLengthnumberYesNumber of bytes occupied by the buffer. The maximum value is 2147483647.

Error codes

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

IDError Message
401Parameter error.
10200012The ArrayBuffer's constructor cannot be directly invoked.

Example

let arrayBuffer: collections.ArrayBuffer = new collections.ArrayBuffer(10);
console.info("byteLength: " + arrayBuffer.byteLength); // byteLength: 10

slice

slice(begin: number, end?: number): ArrayBuffer

Selects a range of elements in this ArkTS ArrayBuffer to create an ArkTS ArrayBuffer.

System capability: SystemCapability.Utils.Lang

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

Parameters

NameTypeMandatoryDescription
beginnumberYesStart index of the range. If a negative number is passed in, it refers to the index of begin + arrayBuffer.byteLength.
endnumberNoEnd index of the range (exclusive). If a negative number is passed in, it refers to the index of end + arrayBuffer.byteLength. The default value is the length of the original ArkTS ArrayBuffer.

Return value

TypeDescription
ArrayBufferNew ArrayBuffer generated.

Error codes

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

IDError Message
401Parameter error.
10200011The slice method cannot be bound.
10200201Concurrent modification error.

Example

let arrayBuffer: collections.ArrayBuffer = new collections.ArrayBuffer(10);
let slicedBuffer: collections.ArrayBuffer = arrayBuffer.slice(0, 4);
console.info("byteLength: " + slicedBuffer.byteLength); // byteLength: 4

你可能感兴趣的鸿蒙文章

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

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

openharmony 鸿蒙 js-apis-util

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