Lines Matching refs:array
36 An array-like object that can be concatenated. This API extends **ISendable**.
90 Concatenates all elements in this array into a string, with a given separator.
106 | string | String obtained. If the array is empty, an empty string is returned.|
127 Selects a range of elements in this array to create an array.
136 …e. If a negative number is passed in, it refers to the index of **start + array.length**. The defa…
137 …ssed in, it refers to the index of **end + array.length**. The default value is the length of the …
143 | ConcatArray\<T> | New array containing the selected elements.|
157 let slicedArray = concatArray.slice (1, 3); // [2, 3] is returned. The original array remains uncha…
178 | length | number | Yes | No | Number of elements in an ArkTS array.|
187 A constructor used to create an empty ArkTS array.
204 let array = new collections.Array<number>();
211 A constructor used to create an ArkTS array with the given elements.
221 | first | T | Yes | First element to be included in the ArkTS array.|
222 | left | T[] | No | Remaining elements to be included in the ArkTS array. |
235 let array = new collections.Array<number>(1, 2, 3, 4);
241 A constructor used to create an ArkTS array with the given elements.
251 | items | T[] | No | Elements to be included in the ArkTS array. |
266 let array = new collections.Array<number>(...arrayPara);
273 Creates an ArkTS array of a fixed length, with each element set to a given initial value.
283 | arrayLength | number | Yes | Length of the ArkTS array.|
284 | initialValue | T | Yes | Initial value of each element in the ArkTS array.|
290 | Array\<T> | Newly created ArkTS array.|
303 let array = collections.Array.create<number>(3, 10); // [10, 10, 10]
310 Creates an ArkTS array from an array-like object.
326 | Array\<T> | Newly created ArkTS array.|
340 let array: Array<string> = ['str1', 'str2', 'str3']; // Native Array<T>, where T is the sendable da…
341 let sendableArray = collections.Array.from<string>(array); // Returns Sendable Array<T>.
347 let array: Array<Array<string>> = [['str1', 'str2', 'str3'], ['str4', 'str5', 'str6'], ['str7', 'st…
348 let sendableArray = collections.Array.from<Array<string>>(array); // Prints the following exception…
355 …last element from this ArkTS array and returns that element. If the array is empty, **undefined** …
365 | T \| undefined | Element removed. If the array is empty, **undefined** is returned.|
379 let array = new collections.Array<number>(1, 2, 3);
380 let lastElement = array.pop(); // 3 is returned. The array changes to [1, 2].
387 Adds one or more elements to the end of this ArkTS array and returns the new length of the array.
403 | number | New length of the array.|
417 let array = new collections.Array<number>(1, 2, 3);
418 let length = array.push (4, 5); // 5 is returned. The array changes to [1, 2, 3, 4, 5].
425 Concatenates all elements in this ArkTS array into a string, with a given separator.
441 | string | String obtained. If the array is empty, an empty string is returned.|
455 let array = new collections.Array<string>('a', 'b', 'c');
456 let joinedString = array.join('-'); // "a-b-c" is returned.
463 …irst element from this ArkTS array and returns that element. If the array is empty, **undefined** …
473 | T \| undefined | Element removed. If the array is empty, **undefined** is returned.|
487 let array = new collections.Array<number>(1, 2, 3);
488 let firstElement = array.shift(); // 1 is returned. The array changes to [2, 3].
495 …s one or more elements to the beginning of this ArkTS array and returns the new length of the arra…
511 | number | New length of the array.|
525 let array = new collections.Array<number>(1, 2, 3);
526 let newLength = array.unshift(0); // 4 is returned. The array changes to [0, 1, 2, 3].
533 Selects a range of elements in this ArkTS array to create an array.
542 …e. If a negative number is passed in, it refers to the index of **start + array.length**. The defa…
543 …ssed in, it refers to the index of **end + array.length**. The default value is the length of the …
549 | Array\<T> | New array containing the selected elements.|
563 let array = new collections.Array<number>(1, 2, 3, 4, 5);
564 let slicedArray = array.slice (1, 3); // [2, 3] is returned. The original array remains unchanged.
571 Sorts elements in this ArkTS array and returns a new array.
601 let array = new collections.Array<number>(1, 3, 5, 4, 2);
602 array.sort((a: number, b: number) => a - b); // [1, 2, 3, 4, 5]
603 array.sort((a: number, b: number) => b - a); // [5, 4, 3, 2, 1]
641 let array = new collections.Array<string>('a', 'b', 'c');
642 let index = array.indexOf('b'); // 1 is returned because 'b' is at index 1.
647 forEach(callbackFn: (value: T, index: number, array: Array\<T>) => void): void
659 | callbackFn | (value: T, index: number, array: Array\<T>) => void | Yes | Callback function to ru…
673 let array = new collections.Array<string>('a', 'b', 'c');
674 array.forEach((value, index, array) => {
681 map\<U>(callbackFn: (value: T, index: number, array: Array\<T>) => U): Array\<U>
683 Calls a callback function for each element in this ArkTS Array and returns a new array that contain…
693 | callbackFn | (value: T, index: number, array: Array\<T>) => U | Yes | Callback function to run f…
699 | Array\<U> | New array containing the result of the callback function.|
713 // Convert each string element in the original array to uppercase and return a new array containing…
714 let array = new collections.Array<string>('a', 'b', 'c');
715 let mappedArray = array.map((value, index, array) => {
723 filter(predicate: (value: T, index: number, array: Array\<T>) => boolean): Array\<T>
725 Returns a new array containing all elements that pass a test provided by a callback function.
735 | predicate | (value: T, index: number, array: Array\<T>) => boolean | Yes | Function that takes t…
741 | Array\<T> | New array containing elements that pass the test.|
755 let array = new collections.Array<number>(1, 2, 3, 4, 5);
756 let filteredArray = array.filter((value: number) => value % 2 === 0); // [2, 4] is returned. This n…
761 reduce(callbackFn: (previousValue: T, currentValue: T, currentIndex: number, array: Array\<T>) => T…
763 Calls a callback function for each element in this ArkTS array, uses the previous return value of t…
773 | callbackFn | (previousValue: T, currentValue: T, currentIndex: number, array: Array\<T>) => T | Y…
793 let array = new collections.Array<number>(1, 2, 3, 4, 5);
794 let reducedValue = array.reduce((accumulator, value) => accumulator + value); // 15, which is the f…
799 reduce\<U>(callbackFn: (previousValue: U, currentValue: T, currentIndex: number, array: Array\<T>) …
801 …tial value as the second parameter to initialize the accumulator before the array traversal starts.
811 | callbackFn | callbackFn: (previousValue: U, currentValue: T, currentIndex: number, array: Array…
832 …used. The accumulator is used to calculate the sum of all elements in the array and return the sum.
833 let array = new collections.Array(1, 2, 3, 4, 5);
834 let reducedValue = array.reduce<number>((accumulator: number, value: number) => accumulator + value…
841 Returns the element at a given index in this ArkTS array.
851 …he index in an array always starts from 0 and is an integer. If a negative number is passed in, it…
872 let array = new collections.Array<number>(1, 2, 3, 4, 5);
873 let elementAtIndex = array.at(2); // 3 is returned. This is because the index starts from 0.
880 Returns an iterator object that contains the key-value pair of each element in this ArkTS array.
890 …ator<[number, T]> | Iterator object that contains the key-value pair of each element in the array.|
904 let array = new collections.Array<number>(1, 2, 3, 4, 5);
905 let iterator = array.entries();
913 Returns an iterator object that contains the key of each element in this ArkTS array.
923 | IterableIterator\<number> | Iterator object that contains the key of each element in the array.|
937 let array = new collections.Array<number>(1, 2, 3, 4, 5);
938 let iterator = array.keys();
948 Returns an iterator object that contains the value of each element in this ArkTS array.
958 | IterableIterator\<T> | Iterator object that contains the value of each element in the array.|
972 let array = new collections.Array<number>(1, 2, 3, 4, 5);
973 let iterator = array.values();
1013 let array = new collections.Array<number>(1, 2, 3, 4, 5);
1014 let foundValue = array.find((value: number) => value % 2 === 0); // 2, the first even element, is r…
1021 Checks whether this ArkTS array contains an element and returns a Boolean value.
1052 let array = new collections.Array<number>(1, 2, 3, 4, 5);
1053 let includesResult = array.includes(3); // true is returned, because the array contains 3.
1090 let array = new collections.Array<number>(1, 2, 3, 4, 5);
1091 let foundIndex = array.findIndex((value: number) => value % 2 === 0); // 1 is returned, because 2 i…
1098 Fills elements in the specified range of this ArkTS array with a given value.
1110 …ex of the range (exclusive). If no value is passed in, it refers to the last element of the array.|
1116 | Array\<T> | Filled array.|
1130 let array = new collections.Array(1, 2, 3, 4, 5);
1131 array.fill(0, 1, 3); // [1, 0, 0, 4, 5] is returned, because elements in the index range from 1 to …
1138 Shrinks this ArkTS array to a given length.
1148 …er | Yes | New length of the array. If a value greater than or equal to the current array length…
1163 array1.shrinkTo(1); // The array is changed to [1].
1166 array2.shrinkTo(10); // The array remains unchanged.
1173 Extends this array to a given length by adding elements with the specified initial value.
1183 …ber | Yes | New length of the array. If a value less than or equal to the current array length i…
1199 array1.extendTo (5, 10); // The array is changed to [1, 2, 3, 10, 10].
1202 array2.extendTo (1, 10); // The array remains unchanged.
1209 Concatenates this ArkTS array with one or more arrays.
1225 | Array\<T> | New array generated.|
1233 | 401 | Parameter error. Not a valid array. |
1240 let array = new collections.Array(1, 2, 3);
1244 let concatArray = array.concat(array1, array2); // The concatenated array is [1, 2, 3, 4, 5, 6, 7, …
1251 Removes elements from a specified position in an array.
1261 …hich the removal starts. If -array.length =< start < 0, the removal starts from **start + array.le…
1282 let array = new collections.Array<number>(1, 2, 3, 4, 5);
1283 let removeArray = array.splice(2); // The array is changed to [1, 2], and [3, 4, 5] is returned.
1290 Removes elements from a specified position in an array, and inserts new elements from the same posi…
1300 …hich the removal starts. If -array.length =< start < 0, the removal starts from **start + array.le…
1302 …he **start** position. If no value is passed in, only the elements in the array are removed. …
1324 let array = new collections.Array<number>(1, 2, 3, 4, 5);
1325 let removeArray = array.splice(2, 2); // The array is changed to [1, 2, 5], and [3, 4] is returned.
1330 let array = new collections.Array<number>(1, 2, 3, 4, 5);
1331 let removeArray = array.splice(2, 2, 6, 7, 8); // The array is changed to [1, 2, 6, 7, 8, 5], and […
1365 let array= new collections.Array<number>(1, 2, 3, 4);
1367 for (let item of array) {
1376 Returns the element at a given index in this array.
1390 | T | Element in the array. |
1404 let array = new collections.Array<number>(1, 2, 4);
1405 console.info("Element at index 1: ", array[1]);
2341 Underlying data structure of the ArkTS typed array.
2425 Describes the mapping function of the ArkTS typed array.
2435 …ElementType | Yes| Element that is currently traversed and used to construct an ArkTS typed array.|
2445 type TypedArrayPredicateFn\<ElementType, ArrayType> = (value: ElementType, index: number, array: Ar…
2447 Describes the assertion function of the ArkTS typed array.
2457 | value | ElementType | Yes| Element that is being traversed in the ArkTS typed array.|
2459 | array | ArrayType | Yes| ArkTS typed array that is being traversed.|
2468 type TypedArrayForEachCallback\<ElementType, ArrayType> = (value: ElementType, index: number, array…
2470 Describes the traversal function of the ArkTS typed array.
2480 | value | ElementType | Yes| Element that is being traversed in the ArkTS typed array.|
2482 | array | ArrayType | Yes| ArkTS typed array that is being traversed.|
2485 type TypedArrayMapCallback\<ElementType, ArrayType> = (value: ElementType, index: number, array: Ar…
2487 Describes the conversion mapping function of the ArkTS typed array.
2497 | value | ElementType | Yes| Element that is being mapped in the ArkTS typed array.|
2499 | array | ArrayType | Yes| ArkTS typed array that is being mapped.|
2508 …(previousValue: AccType, currentValue: ElementType, currentIndex: number, array: ArrayType) => Acc…
2510 Describes the reduce function of the ArkTS typed array.
2521 | currentValue | ElementType | Yes| Element that is being traversed in the ArkTS typed array.|
2523 | array | ArrayType | Yes| ArkTS typed array that is being traversed.|
2534 Describes the sort function of the ArkTS typed array.
2558 - TypedArray: ArkTS typed array of the preceding eight types.
2568 | buffer | ArrayBuffer | Yes | No | Bottom-layer buffer used by an ArkTS typed array.|
2569 | byteLength | number | Yes | No | Number of bytes occupied by the ArkTS typed array.|
2570 | byteOffset | number | Yes | No | Offset between the ArkTS typed array and the start position of…
2571 | length | number | Yes | No | Number of elements in the ArkTS typed array.|
2572 …ELEMENT | number | Yes | No | Number of bytes occupied by each element in the ArkTS typed array.|
2577 A constructor used to create an empty ArkTS typed array.
2607 A constructor used to create an ArkTS typed array of a given length.
2617 | length | number | Yes| Length of the ArkTS typed array.|
2643 constructor(array: ArrayLike\<number> | ArrayBuffer)
2645 A constructor that creates an ArkTS typed array from an array-like object or ArkTS ArrayBuffer.
2655 | array | ArrayLike\<number> \| ArrayBuffer | Yes| Object used to construct the ArkTS typed array.…
2668 // Example 1: Construct an object from an array-like object.
2670 let array: collections.Uint32Array = new collections.Uint32Array(arrayLike);
2674 // Example 2: Construct an object from an ArkTS typed array.
2676 let array: collections.Uint32Array = new collections.Uint32Array(arrayBuffer);
2680 // Example 3: Construct an object from another ArkTS typed array.
2691 A constructor that creates an ArkTS typed array from an ArrayBuffer.
2701 | buffer | ArrayBuffer | Yes| ArrayBuffer object used to construct the ArkTS typed array. The numbe…
2703 | length | number | No| Length of the ArkTS typed array. The default value is **0**.|
2726 Creates an ArkTS typed array from an array-like or iterator object.
2736 | arrayLike | ArrayLike\<number> | Yes| Array-like object used to construct the ArkTS typed array.|
2742 | TypedArray | New ArkTS typed array generated.|
2747 let array: collections.Uint32Array = collections.Uint32Array.from(arrayLike);
2754 Creates an ArkTS typed array from an array-like object.
2763 | arrayLike | ArrayLike\<T> | Yes| Array-like object used to construct the ArkTS typed array. …
2770 | TypedArray | New ArkTS typed array generated.|
2775 // Example 1: Create an ArkTS typed array from an object.
2776 let array: collections.Uint32Array = collections.Uint32Array.from<number>(
2782 // Example 2: Create an ArkTS typed array from a string array.
2783 let array: collections.Uint32Array = collections.Uint32Array.from<string>(
2789 // Example 3: Create an ArkTS typed array from a string.
2790 let array: collections.Uint32Array = collections.Uint32Array.from<string>(
2798 Creates an ArkTS typed array from an iterator object.
2807 | iterable | Iterable\<number> | Yes| Iterator object used to construct the ArkTS typed array. |
2814 | TypedArray | New ArkTS typed array generated.|
2821 let array: collections.Uint32Array = collections.Uint32Array.from(set);
2828 let array: collections.Uint32Array = collections.Uint32Array.from(
2836 Copies elements within a given range from this ArkTS typed array to another position in sequence.
2848 …he index of **end + typedarray.length**. The default value is the length of the ArkTS typed array.|
2854 | TypedArray | ArkTS typed array after being modified.|
2868 let array: collections.Uint32Array = collections.Uint32Array.from([1, 2, 3, 4, 5, 6, 7, 8]);
2869 let copied: collections.Uint32Array = array.copyWithin(3, 1, 3);
2876 Checks whether any element in this ArkTS typed array meets a given condition.
2917 Checks whether all elements in this ArkTS typed array meet a given condition.
2958 Fills all elements in a given range in this ArkTS typed array with a value.
2970 …he index of **end + typedarray.length**. The default value is the length of the ArkTS typed array.|
2976 | TypedArray | Filled ArkTS typed array.|
2999 Returns a new ArkTS typed array that contains all elements that meet the given condition.
3015 | TypedArray| Filtered ArkTS typed array.|
3029 let array: collections.Uint32Array = collections.Uint32Array.from([0, 1, 2, 3, 4]);
3030 let filtered: collections.Uint32Array = array.filter((element: number) => element % 2 == 0);
3067 let array: collections.Uint32Array = collections.Uint32Array.from([0, 1, 2, 3, 4]);
3068 array.find((element: number) => element > 2); // 3
3069 array.find((element: number) => element > 4); // undefined
3105 const array: collections.Uint32Array = collections.Uint32Array.from([1, 2, 3, 4, 5]);
3106 let foundIndex: number = array.findIndex((element: number) => element % 2 === 0); // 1
3112 Calls a callback function for each element in this ArkTS typed array.
3138 uint32Array.forEach((value: number, index: number, array: collections.Uint32Array) => {
3146 Returns the index of the first occurrence of a value in this ArkTS typed array. If the value is not…
3157 …f the ArkTS typed array, **-1** is returned. If a negative number is passed in, the search starts …
3177 let array: collections.Uint32Array = collections.Uint32Array.from([3, 5, 9]);
3178 array.indexOf(3); // 0
3179 array.indexOf(7); // -1
3180 array.indexOf(9, 2); // 2
3181 array.indexOf(9, -2); // 2
3187 Concatenates all elements in this ArkTS typed array into a string, with a given separator.
3203 | string | String obtained. If the array is empty, an empty string is returned.|
3217 let array: collections.Uint32Array = collections.Uint32Array.from([1, 2, 3, 4, 5]);
3218 let joined: string = array.join('-'); // "1-2-3-4-5"
3224 …ck function to each element in this ArkTS typed array and uses the result to create an ArkTS typed…
3240 | TypedArray | New ArkTS typed array generated.|
3254 let array: collections.Uint32Array = collections.Uint32Array.from([25, 36, 49]);
3255 const mapped: collections.Uint32Array = array.map(Math.sqrt); // Uint32Array [5, 6 ,7]
3261 Applies a reduce function on each element in this ArkTS typed array and returns the final reduction…
3290 let array: collections.Uint32Array = collections.Uint32Array.from([1, 2, 3, 4, 5]);
3291 let reducedValue: number = array.reduce((accumulator: number, value: number) => accumulator + value…
3298 Applies a reduce function for each element in this ArkTS typed array, receives an initial value as …
3329 let array: collections.Uint32Array = collections.Uint32Array.from([1, 2, 3, 4, 5]);
3330 let reducedValue: number = array.reduce((accumulator: number, value: number) => accumulator + value…
3337 Applies a reduce function for each element in this ArkTS typed array, receives an initial value as …
3368 let array: collections.Uint32Array = collections.Uint32Array.from([1, 2, 3, 4, 5]);
3369 let reducedValue: string = array.reduce<string>((accumulator: string, value: number) => accumulator…
3376 Reverses this ArkTS typed array.
3386 | TypedArray | Reversed ArkTS typed array.|
3400 let array: collections.Uint32Array = collections.Uint32Array.from([1, 2, 3, 4, 5]);
3401 let reversed: collections.Uint32Array = array.reverse(); // Uint32Array [5, 4, 3, 2, 1]
3405 set(array: ArrayLike\<number>, offset?: number): void
3407 Writes the elements in an array-like object to the given start position in sequence.
3416 | array | ArrayLike\<number> | Yes | Array-like object whose elements will be written.|
3432 let array: collections.Uint8Array = new collections.Uint8Array(buffer);
3433 array.set([1, 2, 3], 3); // Uint8Array [0, 0, 0, 1, 2, 3, 0, 0]
3439 Selects a range of elements in this ArkTS typed array to create an ArkTS typed array.
3450 …he index of **end + typedarray.length**. The default value is the length of the ArkTS typed array.|
3456 | TypedArray | New ArkTS typed array generated.|
3470 let array: collections.Uint32Array = collections.Uint32Array.from([1, 2, 3, 4, 5]);
3471 array.slice(); // Uint32Array [1, 2, 3, 4, 5]
3472 array.slice(1, 3); // Uint32Array [2, 3]
3473 array.slice(-2); // Uint32Array [4, 5]
3479 Sorts elements in this ArkTS typed array and returns the sorted ArkTS typed array.
3495 | TypedArray | Sorted ArkTS typed array.|
3509 let array: collections.Uint32Array = collections.Uint32Array.from([1, 3, 5, 4, 2]);
3510 array.sort(); // Uint32Array [1, 2, 3, 4, 5]
3511 array.sort((a: number, b: number) => a - b); // Uint32Array [1, 2, 3, 4, 5]
3512 array.sort((a: number, b: number) => b - a); // Uint32Array [5, 4, 3, 2, 1]
3518 Returns a new ArkTS typed array based on the same ArkTS ArrayBuffer.
3529 …he index of **end + typedarray.length**. The default value is the length of the ArkTS typed array.|
3535 | TypedArray | New ArkTS typed array generated.|
3549 let array: collections.Uint32Array = collections.Uint32Array.from([1, 2, 3, 4, 5]);
3550 let subArray: collections.Uint32Array = array.subarray(); // Uint32Array [1, 2, 3, 4, 5]
3566 | index | number | Yes | Index of the element. The index in an array always starts from 0 and is …
3586 let array: collections.Uint32Array = collections.Uint32Array.from([1, 2, 3, 4, 5]);
3587 console.info("element: " + array.at(2)); // element: 3
3588 console.info("element: " + array.at(-1)); // element: 5
3589 console.info("element: " + array.at(6)); // element: undefined
3595 Checks whether elements are contained in this ArkTS typed array.
3626 let array: collections.Uint32Array = collections.Uint32Array.from([1, 2, 3]);
3627 console.info("includes: " + array.includes(2)); // includes: true
3628 console.info("includes: " + array.includes(4)); // includes: false
3629 console.info("includes: " + array.includes(3, 3)); // includes: false
3635 …urns an iterator object that contains the key-value pair of each element in this ArkTS typed array.
3659 let array: collections.Uint32Array = collections.Uint32Array.from([11, 22, 33]);
3660 let iterator: IterableIterator<[number, number]> = array.entries();
3669 Returns an iterator object that contains the key (index) of each element in this ArkTS typed array.
3693 let array: collections.Uint32Array = collections.Uint32Array.from([1, 2, 3, 4, 5]);
3694 let iterator: IterableIterator<number> = array.keys();
3703 Returns an iterator object that contains the value of each element in this ArkTS typed array.
3727 let array: collections.Uint32Array = collections.Uint32Array.from([1, 2, 3, 4, 5]);
3728 let iterator: IterableIterator<number> = array.values();