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(): T
Description: Remove and return the last element from array.
In
Wasmnizer-ts
, we will regard the union typeT | undefined
as any type, so we only defineT
as 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(): T
Description: Remove and return the first element from array.
In
Wasmnizer-ts
, we will regard the union typeT | undefined
as any type, so we only defineT
as 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
,this
represents 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): boolean
Description: Applies a provided callback function
predicate
to each element in the array and returnstrue
if the callback returnstrue
for every element, otherwise, it returnsfalse
.We set the
predicate callback function
's return type to boolean, and the second parameterthisArg
in the standard library has been deleted. -
some(predicate: (value: T, index: number, array: T[]) => boolean): boolean
Description: Applies a provided callback function
predicate
to each element in the array and returnstrue
if the callback returnstrue
for at least one element, otherwise, it returnsfalse
.We set the
predicate callback function
's return type to boolean, and the second parameterthisArg
in the standard library has been deleted. -
forEach(callbackfn: (value: T, index: number, array: T[]) => void): void
Description: Iterate over the elements of an array and apply provided callback function
callbackfn
to each element.The second parameter
thisArg
in 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
callbackfn
to each element.The second parameter
thisArg
in 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 parameterthisArg
in 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 parameterthisArg
in the standard library has been deleted, sincefind
is always returnundefined
, so we setany
type to representT | undefined
. -
findIndex(predicate: (value: T, index: number, obj: T[]) => boolean): number
Description: 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 parameterthisArg
in 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
,this
represents class instance, so the return type is set toT[]
notthis
.