The standard array APIs are implemented by native. Here we list the APIs supported by Wasmnizer-ts.
Please note that specific implementations may differ slightly from libraries like JavaScript Core Library. For uniform APIs, hyperlinks to their descriptions will be provided. In situations where there are variations, this document offers API descriptions along with explanations for the differences.
-
pop(): TDescription: Remove and return the last element from array.
In
Wasmnizer-ts, we will regard the union typeT | undefinedas any type, so we only defineTas return type here. -
concat(...items: T[]): T[]Description: Concatenate multiple arrays and returns a new array containing the merged elements.
We simply set the
items's type toT[]. -
shift(): TDescription: Remove and return the first element from array.
In
Wasmnizer-ts, we will regard the union typeT | undefinedas any type, so we only defineTas return type here. -
sort(compareFn: (a: T, b: T) => number): T[]Description: Sort the elements of an array in place and return the sorted array by a comparison function
compareFn.In
Wasmnizer-ts,thisrepresents class instance, so the return type is set toT[]notthis. -
splice(start: number, deleteCount?: number, ...items: T[]): T[]Description: Change the contents of an array by removing, replacing, or adding elements.
Combines two standard APIs:
splice(start: number, deleteCount?: number): T[];andsplice(start: number, deleteCount: number, ...items: T[]): T[];. -
every(predicate: (value: T, index: number, array: T[]) => boolean): booleanDescription: Applies a provided callback function
predicateto each element in the array and returnstrueif the callback returnstruefor every element, otherwise, it returnsfalse.We set the
predicate callback function's return type to boolean, and the second parameterthisArgin the standard library has been deleted. -
some(predicate: (value: T, index: number, array: T[]) => boolean): booleanDescription: Applies a provided callback function
predicateto each element in the array and returnstrueif the callback returnstruefor at least one element, otherwise, it returnsfalse.We set the
predicate callback function's return type to boolean, and the second parameterthisArgin the standard library has been deleted. -
forEach(callbackfn: (value: T, index: number, array: T[]) => void): voidDescription: Iterate over the elements of an array and apply provided callback function
callbackfnto each element.The second parameter
thisArgin the standard library has been deleted. -
map<U>(callbackfn: (value: T, index: number, array: T[]) => U): U[]Description: Return a new array containing the results of applying the callback function
callbackfnto each element.The second parameter
thisArgin the standard library has been deleted. -
filter(predicate: (value: T, index: number, array: T[]) => boolean): T[]Description: Return a new array containing elements that satisfy the condition specified in the callback function
predicate.We set the
predicate callback function's return type to boolean, and the second parameterthisArgin the standard library has been deleted. -
find(predicate: (value: T, index: number, obj: T[]) => boolean): any**Description: Search for and return the first element in an array that satisfies a specified condition defined by a provided callback function
predicate, otherwise, returnundefined.We set the
predicate callback function's return type to boolean, the second parameterthisArgin the standard library has been deleted, sincefindis always returnundefined, so we setanytype to representT | undefined. -
findIndex(predicate: (value: T, index: number, obj: T[]) => boolean): numberDescription: Return the index of the first element in an array that satisfies a specified condition defined by a provided callback function
predicate, otherwise, return -1.We set the
predicate callback function's return type to boolean, and the second parameterthisArgin the standard library has been deleted. -
copyWithin(target: number, start: number, end?: number): T[]Description: Copy a portion of an array to another location within the same array.
In
Wasmnizer-ts,thisrepresents class instance, so the return type is set toT[]notthis.