source
stringlengths
14
113
code
stringlengths
10
21.3k
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let concatArray : collections.ConcatArray<number> = new collections.Array<number>(1, 2, 4); console.info("Element at index 1: ", concatArray[1]);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let concatArray : collections.ConcatArray<string> = new collections.Array<string>('a', 'b', 'c'); let joinedString = concatArray.join('-'); // "a-b-c" is returned.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
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.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>();
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3, 4);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let arrayPara = [1,2,3]; let array = new collections.Array<number>(...arrayPara);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = collections.Array.create<number>(3, 10); // [10, 10, 10]
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Positive example: let array: Array<string> = ['str1', 'str2', 'str3']; // Native Array<T>, where T is the sendable data type. let sendableArray = collections.Array.from<string>(array); // Returns Sendable Array<T>.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Negative example: let array: Array<Array<string>> = [['str1', 'str2', 'str3'], ['str4', 'str5', 'str6'], ['str7', 'str8', 'str9']]; // Native Array<T>, where T is a non-sendable data type. let sendableArray = collections.Array.from<Array<string>>(array); // Prints the following exception information: Parameter error...
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Positive example: const mapper = new Map([ ['1', 'a'], ['2', 'b'], ]); let newArray: collections.Array<string> = collections.Array.from(mapper.values()); console.info(newArray.toString()); // Expected output: a,b
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array : Array<number> = [1, 2, 3]; // Native Array<T>, where T is of the Sendable type. let newarray = collections.Array.from<number>(array, (value, index) => value + index); // Return a new Array<T>. console.info(newarray.toString()); // Expected output: 1, 3, 5
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array : Array<number> = [1, 2, 3]; // Native Array<T> let newarray = collections.Array.from<number, string>(array, (value, index) => value + "." + index); // Return a new Array<T>. console.info(newarray.toString()); // Expected output: 1.0, 2.1, 3.2
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let arr: collections.Array<string> = new collections.Array('a', 'b', 'c', 'd'); let result: boolean = collections.Array.isArray(arr); console.info(result + ''); // Expected output: true
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let arr: collections.Array<string> = collections.Array.of('a', 'b', 'c', 'd'); console.info(arr.toString()); // Expected output: a, b, c, d
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array: collections.Array<number> = collections.Array.from([1, 2, 3, 4, 5, 6, 7, 8]); let copied: collections.Array<number> = array.copyWithin(3, 1, 3); console.info(copied.toString()); // Expected output: 1, 2, 3, 2, 3, 6, 7, 8
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array: collections.Array<number> = collections.Array.from([3, 5, 9]); console.info(array.lastIndexOf(3) + ''); // Expected output: 0 console.info(array.lastIndexOf(7) + ''); // Expected output: -1 console.info(array.lastIndexOf(9, 2) + ''); // Expected output: 2 console.info(array.lastIndexOf(9, -2) + ''); // Expec...
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let newArray: collections.Array<number> = collections.Array.from([-10, 20, -30, 40, -50]); console.info(newArray.some((element: number) => element < 0) + ''); // Expected output: true
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3, 4, 5); let reducedValue = array.reduceRight((accumulator, value) => accumulator + value); // Accumulated result of all elements. console.info(reducedValue + ''); // Expected output: 15
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// An accumulator with the initial value 0 is used. The accumulator is used to calculate the sum of all elements in the array and return the sum. let array = new collections.Array<number>(1, 2, 3, 4, 5); let reducedValue = array.reduceRight<number>((accumulator: number, value: number) => accumulator + value, 0); // Acc...
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3); let lastElement = array.pop(); // 3 is returned. The array changes to [1, 2].
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3); let length = array.push (4, 5); // 5 is returned. The array changes to [1, 2, 3, 4, 5].
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<string>('a', 'b', 'c'); let joinedString = array.join('-'); // "a-b-c" is returned.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3); let firstElement = array.shift(); // 1 is returned. The array changes to [2, 3].
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3, 4, 5); let reversed = array.reverse(); console.info(array.toString()); // Expected output: 5, 4, 3, 2, 1
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3); let newLength = array.unshift(0); // 4 is returned. The array changes to [0, 1, 2, 3].
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3, 4, 5); let stringArray = array.toString(); console.info(stringArray); // Expected output: 1,2,3,4,5
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3, 4, 5); let slicedArray = array.slice (1, 3); // [2, 3] is returned. The original array remains unchanged.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 3, 5, 4, 2); array.sort((a: number, b: number) => a - b); // [1, 2, 3, 4, 5] array.sort((a: number, b: number) => b - a); // [5, 4, 3, 2, 1]
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<string>('a', 'b', 'c'); let index = array.indexOf('b'); // 1 is returned because 'b' is at index 1.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<string>('a', 'b', 'c'); array.forEach((value, index, array) => { console.info(`Element ${value} at index ${index}`); });
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Convert each string element in the original array to uppercase and return a new array containing the new strings. let array = new collections.Array<string>('a', 'b', 'c'); let mappedArray = array.map((value, index, array) => { return value.toUpperCase(); // Convert each string element to uppercase. }); console.inf...
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3, 4, 5); let filteredArray = array.filter((value: number) => value % 2 === 0); // [2, 4] is returned. This new array contains only even numbers.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3, 4, 5); let reducedValue = array.reduce((accumulator, value) => accumulator + value); // 15, which is the final accumulated result of all elements, is returned.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// An accumulator with the initial value 0 is used. The accumulator is used to calculate the sum of all elements in the array and return the sum. let array = new collections.Array(1, 2, 3, 4, 5); let reducedValue = array.reduce<number>((accumulator: number, value: number) => accumulator + value, 0); // 15, which is the...
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3, 4, 5); let elementAtIndex = array.at(2); // 3 is returned. This is because the index starts from 0.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3, 4, 5); let iterator = array.entries(); console.info(iterator.next().value); // [0, 1], key-value pair of the first element is returned.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3, 4, 5); let iterator = array.keys(); for (const key of iterator) { console.info("" + key); // 0, 1, 2, 3, and 4 are returned in sequence. }
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3, 4, 5); let iterator = array.values(); for(const value of iterator) { console.info("" + value); // 1, 2, 3, 4, and 5 are returned in sequence. }
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3, 4, 5); let foundValue = array.find((value: number) => value % 2 === 0); // 2, the first even element, is returned.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3, 4, 5); let includesResult = array.includes(3); // true is returned, because the array contains 3.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3, 4, 5); let foundIndex = array.findIndex((value: number) => value % 2 === 0); // 1 is returned, because 2 is the first even element.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array(1, 2, 3, 4, 5); array.fill(0, 1, 3); // [1, 0, 0, 4, 5] is returned, because elements in the index range from 1 to 3 are filled with 0.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array1 = new collections.Array(1, 2, 3, 4, 5); array1.shrinkTo(1); // The array is changed to [1]. let array2 = new collections.Array(1, 2, 3, 4, 5); array2.shrinkTo(10); // The array remains unchanged.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array1 = new collections.Array(1, 2, 3); array1.extendTo (5, 10); // The array is changed to [1, 2, 3, 10, 10]. let array2 = new collections.Array(1, 2, 3); array2.extendTo (1, 10); // The array remains unchanged.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array(1, 2, 3); let array1 = new collections.Array(4, 5, 6); let array2 = new collections.Array(7, 8, 9); let concatArray = array.concat(array1, array2); // The concatenated array is [1, 2, 3, 4, 5, 6, 7, 8, 9].
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 3, 4, 5); let removeArray = array.splice(2); // The array is changed to [1, 2], and [3, 4, 5] is returned.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let newArray: collections.Array<number> = collections.Array.from([-10, 20, -30, 40, -50]); console.info(newArray.every((element: number) => element > 0) + ''); // Expected output: false
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// The system where the application is running is set to the French locale. let array = new collections.Array<number | string>(1000, 'Test', 53621); let stringArray = array.toLocaleString(); console.info(stringArray); // Expected output: 1,000,Test,53,621
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Example 1: let array = new collections.Array<number>(1, 2, 3, 4, 5); let removeArray = array.splice(2, 2); // The array is changed to [1, 2, 5], and [3, 4] is returned.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Example 2: let array = new collections.Array<number>(1, 2, 3, 4, 5); let removeArray = array.splice(2, 2, 6, 7, 8); // The array is changed to [1, 2, 6, 7, 8, 5], and [3, 4] is returned.
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array= new collections.Array<number>(1, 2, 3, 4); for (let item of array) { console.info(`value : ${item}`); }
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Array<number>(1, 2, 4); console.info("Element at index 1: ", array[1]);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Positive example 1: const myMap = new collections.Map<number, number>();
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Positive example 2: const myMap = new collections.Map<number, string>([ [1, "one"], [2, "two"], [3, "three"], ]);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Negative example: @Sendable class SharedClass { constructor() { } } let sObj = new SharedClass(); const myMap1: collections.Map<number, SharedClass> = new collections.Map<number, SharedClass>([[1, sObj]]); // Type arguments of generic "Sendable" type must be a "Sendable" data type (arkts-sendable-generic-types) ...
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Example 1: const myMap = new collections.Map<number, string>([ [0, "foo"], [1, "bar"] ]); const iterator = myMap.entries(); // Expected output: [0, "foo"] console.info(iterator.next().value); // Expected output: [1, "bar"] console.info(iterator.next().value);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Example 2: const myMap: collections.Map<number, string> = new collections.Map<number, string>([ [0, "one"], [1, "two"], [2, "three"], [3, "four"] ]); const entriesIter: IterableIterator<[number, string]> = myMap.entries(); for (const entry of entriesIter) { if (entry[1].startsWith('t')) { myMap.delete(...
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
const myMap = new collections.Map<number, string>([ [0, "foo"], [1, "bar"] ]); const iterator = myMap.keys(); // Expected output: 0 console.info(iterator.next().value); // Expected output: 1 console.info(iterator.next().value);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
const myMap = new collections.Map<number, string>([ [0, "foo"], [1, "bar"] ]); const iterator = myMap.values(); // Expected output: "foo" console.info(iterator.next().value); // Expected output: "bar" console.info(iterator.next().value);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
const myMap = new collections.Map<number, string>([ [0, "foo"], [1, "bar"] ]); // Expected output: 2 console.info("size:" + myMap.size); myMap.clear(); // Expected output: 0 console.info("size:" + myMap.size);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
const myMap = new collections.Map<string, string>([ ["hello", "world"], ]); // Expected result: true console.info("result:" + myMap.delete("hello")); // Expected result: false console.info("result:" + myMap.has("hello")); // Expected result: false console.info("result:" + myMap.delete("hello"));
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Positive example: new collections.Map<string, number>([ ['foo', 0], ['bar', 1], ['baz', 2], ]).forEach((value, key, map) => { console.info(`m[${key}] = ${value}`); });
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Negative example: new collections.Map<string, number>([ ['foo', 0], ['bar', 1], ['baz', 2], ]).forEach((value, key, map) => { // Throw exception `Concurrent modification exception.` map.delete(key); });
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
const myMap = new collections.Map<string, string>([ ["hello", "world"], ]); // Expected output: "world" console.info(myMap.get("hello")); // Expected output: undefined console.info(myMap.get("world"));
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
const myMap = new collections.Map<string, string>([ ["hello", "world"], ]); // Expected output: true console.info("result:" + myMap.has("hello")); // Expected output: false console.info("result:" + myMap.has("world"));
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Positive example: const myMap = new collections.Map<string, string>(); myMap.set("foo", "bar")
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Negative example: let obj = new Object(); const myMap: collections.Map<string, Object> = new collections.Map<string, Object>(); // Type arguments of generic "Sendable" type must be a "Sendable" data type (arkts-sendable-generic-types) myMap.set("foo", obj);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let map = new collections.Map<number, string>([ [0, "one"], [1, "two"], [2, "three"], [3, "four"] ]); let keys = Array.from(map.keys()); for (let key of keys) { console.info("key:" + key); console.info("value:" + map.get(key)); }
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Positive example 1: const mySet = new collections.Set<number>();
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Positive example 2: const mySet = new collections.Set<number>([1, 2, 3, 4, 5]);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Negative example: @Sendable class SharedClass { constructor() { } } let sObj = new SharedClass(); const mySet1: collections.Set<number|SharedClass> = new collections.Set<number|SharedClass>([1, sObj]); // Type arguments of generic "Sendable" type must be a "Sendable" data type (arkts-sendable-generic-types) let...
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
const mySet = new collections.Set<number>([0, 1, 2, 3]); const iterator = mySet.entries(); // Expected output: [0, 0] console.info(iterator.next().value); // Expected output: [1, 1] console.info(iterator.next().value);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
const mySet = new collections.Set<number>([0, 1, 2, 3]); const iterator = mySet.keys(); // Expected output: 0 console.info(iterator.next().value); // Expected output: 1 console.info(iterator.next().value);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Example 1: const mySet = new collections.Set<number>([0, 1, 2, 3]); const iterator = mySet.values(); // Expected output: 0 console.info(iterator.next().value); // Expected output: 1 console.info(iterator.next().value);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Example 2: const mySet = new collections.Set<number>([0, 1, 2, 3]); const valueIter = mySet.values(); for (let value of valueIter) { if (value % 2 == 0) { mySet.delete(value); } } // Expected output: 2 console.info("size:" + mySet.size);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
const mySet = new collections.Set<number>([0, 1]); // Expected output: 2 console.info("size:" + mySet.size); mySet.clear(); // Expected output: 0 console.info("size:" + mySet.size);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
const mySet = new collections.Set<string>(["hello", "world"]); // Expected result: true console.info("result:" + mySet.delete("hello")); // Expected result: false console.info("result:" + mySet.has("hello")); // Expected result: false console.info("result:" + mySet.delete("hello"));
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Positive example: new collections.Set<string>(['foo', 'bar', 'baz']).forEach((value1, value2, set) => { console.info(`s[${value1}] = ${value2}`); });
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Negative example: new collections.Set<string>(['foo', 'bar', 'baz']).forEach((value1, value2, set) => { // Throw exception `Concurrent modification exception.` set.delete(value1); });
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
const mySet = new collections.Set<string>(["hello", "world"]); // Expected output: true console.info("result:" + mySet.has("hello")); // Expected output: true console.info("result:" + mySet.has("world"));
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Positive example: const mySet: collections.Set<string> = new collections.Set<string>(); mySet.add("foo");
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Negative example: let obj = new Object(); const mySet: collections.Set<Object> = new collections.Set<Object>(); // Type arguments of generic "Sendable" type must be a "Sendable" data type (arkts-sendable-generic-types) mySet.add(obj);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let set = new collections.Set<number>([1, 2, 3, 4, 5]); let val: Array<number> = Array.from(set.values()); for (let item of val) { console.info("value: " + item); }
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let arrayBuffer: collections.ArrayBuffer = new collections.ArrayBuffer(10); console.info("byteLength: " + arrayBuffer.byteLength); // byteLength: 10
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let arrayBuffer: collections.ArrayBuffer = new collections.ArrayBuffer(10); let slicedBuffer: collections.ArrayBuffer = arrayBuffer.slice(0, 4); console.info("byteLength: " + slicedBuffer.byteLength); // byteLength: 4
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let int8Array: collections.Int8Array = new collections.Int8Array(); let uint8Array: collections.Uint8Array = new collections.Uint8Array(); let int16Array: collections.Int16Array = new collections.Int16Array(); let uint16Array: collections.Uint16Array = new collections.Uint16Array(); let int32Array: collections.Int32Arr...
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Construct an object with the length parameter. let int8Array: collections.Int8Array = new collections.Int8Array(12); let uint8Array: collections.Uint8Array = new collections.Uint8Array(12); let int16Array: collections.Int16Array = new collections.Int16Array(12); let uint16Array: collections.Uint16Array = new collect...
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Example 1: Construct an object from an array-like object. let arrayLike = [1, 3, 5]; let array: collections.Uint32Array = new collections.Uint32Array(arrayLike);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Example 2: Construct an object from an ArkTS TypedArray. let arrayBuffer: collections.ArrayBuffer = new collections.ArrayBuffer(12); let array: collections.Uint32Array = new collections.Uint32Array(arrayBuffer);
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Example 3: Construct an object from another ArkTS TypedArray. let arrayLike = [1, 3, 5]; let uint8Array: collections.Uint8Array = new collections.Uint8Array(arrayLike); // Uint8Array [1, 3, 5] let uint32Array: collections.Uint32Array = new collections.Uint32Array(uint8Array); // Uint32Array [1, 3, 5]
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let int32Array: collections.Int32Array = collections.Int32Array.from([1, 2, 3, 4, 5, 6]); console.info("byteLength: " + int32Array.buffer.byteLength); // byteLength: 24 // Start from the fourth byte of the buffer corresponding to int32Array. The length is 5. let uint32Array: collections.Uint32Array = new collections.Ui...
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let arrayLike = [1, 3, 5]; let array: collections.Uint32Array = collections.Uint32Array.from(arrayLike); // Uint32Array [1, 3, 5]
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Example 1: Create an ArkTS TypedArray from an object. let array: collections.Uint32Array = collections.Uint32Array.from<number>( { length: 5 }, (v: Object, k: number) => k); // Uint32Array [0, 1, 2, 3, 4]
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Example 2: Create an ArkTS TypedArray from a string array. let array: collections.Uint32Array = collections.Uint32Array.from<string>( ["1", "3", "5"], (v: string, k: number) => parseInt(v)); // Uint32Array [1, 3, 5]
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Example 3: Create an ArkTS TypedArray from a string. let array: collections.Uint32Array = collections.Uint32Array.from<string>( "12345", (v: string, k: number) => parseInt(v)); // Uint32Array [1, 2, 3, 4, 5]
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Example 1: No mapping function is specified. let set: Set<number> = new Set<number>([1, 2, 3]); let array: collections.Uint32Array = collections.Uint32Array.from(set); // Uint32Array [1, 2, 3]
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// Example 2: A mapping function is specified. let set: Set<number> = new Set<number>([1, 2, 3]); let array: collections.Uint32Array = collections.Uint32Array.from( set, (v: number, k: number) => v + k); // Uint32Array [1, 3, 5]
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let arr: collections.Uint32Array = collections.Uint32Array.of(1, 2, 3, 4); console.info(arr.toString()); // Expected output: 1,2,3,4
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
let array = new collections.Uint32Array([1, 2, 3, 4, 5]); let stringArray = array.toString(); console.info(stringArray); // Expected output: 1,2,3,4,5
application-dev\reference\apis-arkts\js-apis-arkts-collections.md
// The system where the application is running is set to the French locale. let array = new collections.Uint32Array([1000, 2000, 3000]); let stringArray = array.toLocaleString(); console.info(stringArray); // Expected output: 1,000,2,000,3,000