给出Array
对象接口中文注释,以便查询
JavaScript Array
在 Typescript 中的接口
项目 | 类别 | 功能概述 |
---|---|---|
length : number; | 属性 | 获取或设置数组的长度。这比数组中的最高索引高一号。 |
toString (): string; | 函数 | 返回数组的字符串表示形式。 |
toLocaleString (): string; | 函数 | 返回数组的字符串表示形式。这些元素使用它们的toLocaleString方法转换为字符串。 |
pop (): T | undefined; | 函数 | 从数组中移除最后一个元素并返回它。 |
push (…items: T[]): number; | 函数 | 将新元素追加到数组末尾,并返回数组的新长度。 |
concat (…items: ConcatArray<T >[] ): T[] ; | 函数 | 组合两个或多个数组。 |
concat (…items: (T | ConcatArray<T>)[]) : T[] ; | 函数 | 组合两个或多个数组。 |
join (separator?: string): string; | 函数 | 将数组的所有元素添加到字符串中,用指定的分隔符字符串分隔。 |
reverse (): T[] ; | 函数 | 在适当的位置反转数组中的元素。 |
shift (): T | undefined; | 函数 | 从数组中移除第一个元素并返回它。 |
slice (start?: number, end?: number): T[] ; | 函数 | 返回数组某一部分的副本。 |
sort (compareFn?: (a: T , b: T ) => number): this; | 函数 | 对数组进行就地排序。 |
splice (start: number, deleteCount?: number): T[] ; | 函数 | 从数组中移除元素,并在必要时插入新元素,返回删除的元素。 |
splice (start: number, deleteCount: number, …items: T[] ): T[] ; | 函数 | 从数组中移除元素,并在必要时插入新元素,返回删除的元素。 |
unshift (…items: T[] ): number; | 函数 | 在数组的开头插入新元素,并返回数组的新长度。 |
indexOf (searchElement: T , fromIndex?: number): number; | 函数 | 返回数组中第一个值的索引,如果不存在,则返回-1。 |
lastIndexOf (searchElement: T , fromIndex?: number): number; | 函数 | 返回指定值在数组中最后一次出现的索引,如果不存在,则返回-1。 |
every <S extends T >(predicate: (value: T , index: number, array: T[] ) => value is S, thisArg?: any): this is S[]; | 函数 | 确定数组的所有成员是否满足指定的测试 |
some (predicate: (value: T , index: number, array: T[] ) => unknown, thisArg?: any): boolean; | 函数 | 确定对于数组的任何元素,指定的回调函数是否返回true。 |
forEach (callbackfn: (value: T , index: number, array: T[] ) => void, thisArg?: any): void; | 函数 | 为数组中的每个元素执行指定的操作。 |
map <U >(callbackfn: (value: T , index: number, array: T[] ) => U, thisArg?: any): U[] ; | 函数 | 对数组的每个元素调用一个已定义的回调函数,并返回一个包含结果的数组。 |
filter <S extends T >(predicate: (value: T , index: number, array: T[] ) => value is S, thisArg?: any): S[] ; | 函数 | 返回满足回调函数中指定条件的数组元素。 |
filter (predicate: (value: T , index: number, array: T[] ) => unknown, thisArg?: any): T[] ; | 函数 | 返回满足回调函数中指定条件的数组元素。 |
reduce (callbackfn: (previousValue: T , currentValue: T , currentIndex: number, array: T[] ) => T ): T ; | 函数 | 为数组中的所有元素调用指定的回调函数。回调函数的返回值是累积的结果,并在回调函数的下一次调用中作为参数提供。 |
reduce (callbackfn: (previousValue: T , currentValue: T , currentIndex: number, array: T[] ) => T , initialValue: T ): T ; | 函数 | 为数组中的所有元素调用指定的回调函数。回调函数的返回值是累积的结果,并在回调函数的下一次调用中作为参数提供。 |
reduce <U >(callbackfn: (previousValue: U , currentValue: T , currentIndex: number, array: T[] ) => U , initialValue: U ): U ; | 函数 | 为数组中的所有元素调用指定的回调函数。回调函数的返回值是累积的结果,并在回调函数的下一次调用中作为参数提供。 |
reduceRight (callbackfn: (previousValue: T , currentValue: T , currentIndex: number, array: T[] ) => T ): T ; | 函数 | 按降序为数组中的所有元素调用指定的回调函数。回调函数的返回值是累积的结果,并在回调函数的下一次调用中作为参数提供。 |
reduceRight (callbackfn: (previousValue: T , currentValue: T , currentIndex: number, array: T[] ) => T , initialValue: T ): T ; | 函数 | 按降序为数组中的所有元素调用指定的回调函数。回调函数的返回值是累积的结果,并在回调函数的下一次调用中作为参数提供。 |
reduceRight <U >(callbackfn: (previousValue: U , currentValue: T , currentIndex: number, array: T[] ) => U , initialValue: U ): U ; | 函数 | 按降序为数组中的所有元素调用指定的回调函数。回调函数的返回值是累积的结果,并在回调函数的下一次调用中作为参数提供。 |
readonly [n: number]: T ; |
interface Array<T> {
/**
* 获取或设置数组的长度。这比数组中的最高索引高一号。
*/
length: number;
/**
* 返回数组的字符串表示形式。
*/
toString(): string;
/**
* 返回数组的字符串表示形式。这些元素使用它们的toLocaleString方法转换为字符串。
*/
toLocaleString(): string;
/**
* 从数组中移除最后一个元素并返回它。
* 如果数组为空,则返回undefined,并且不修改数组。
*/
pop(): T | undefined;
/**
* 将新元素追加到数组末尾,并返回数组的新长度。
* @param 要添加到数组中的新元素。
*/
push(...items: T[]): number;
/**
* 组合两个或多个数组。
* 此方法返回一个新数组,而不修改任何现有数组。
* @param 项目要添加到数组末尾的附加数组和/或项目。
*/
concat(...items: ConcatArray<T>[]): T[];
/**
* 组合两个或多个数组。
* 此方法返回一个新数组,而不修改任何现有数组。
* @param 项目要添加到数组末尾的附加数组和/或项目。
*/
concat(...items: (T | ConcatArray<T>)[]): T[];
/**
* 将数组的所有元素添加到字符串中,用指定的分隔符字符串分隔。
* @param 分隔符用于将数组中的一个元素与结果字符串中的下一个元素分开的字符串。如果省略,数组元素用逗号分隔。
*/
join(separator?: string): string;
/**
* 在适当的位置反转数组中的元素。
* 此方法变异数组并返回对同一数组的引用。
*/
reverse(): T[];
/**
* 从数组中移除第一个元素并返回它。
* 如果数组为空,则返回undefined,并且不修改数组。
*/
shift(): T | undefined;
/**
* 返回数组某一部分的副本。
* 对于开始和结束,可以使用负索引来指示从数组末尾的偏移量。
* 例如,-2表示数组的倒数第二个元素。
* @param start 数组指定部分的开始索引。
* 如果start未定义,则切片从索引0开始。
* @param end 数组指定部分的结束索引。这不包括索引“end”处的元素。
* 如果end未定义,则切片会延伸到数组的末尾。
*/
slice(start?: number, end?: number): T[];
/**
* 对数组进行就地排序。
* 此方法变异数组并返回对同一数组的引用。
* @param 用于确定元素顺序的比较函数。如果第一个参数小于第二个参数,它应该返回一个负值,如果它们相等,则返回零,否则返回一个正值。如果省略,元素将按升序排列,ASCII字符顺序。
* ```ts
* [11,2,22,1].sort((a, b) => a - b)
* ```
*/
sort(compareFn?: (a: T, b: T) => number): this;
/**
* 从数组中移除元素,并在必要时插入新元素,返回删除的元素。
* @param 数组中从零开始移除元素的位置。
* @param 删除计数要删除的元素数量。
* @returns 包含已删除元素的数组。
*/
splice(start: number, deleteCount?: number): T[];
/**
* 从数组中移除元素,并在必要时插入新元素,返回删除的元素。
* @param 数组中从零开始移除元素的位置。
* @param 删除计数要删除的元素数量。
* @param 项目要插入数组中的元素,以取代已删除的元素。
* @returns 包含已删除元素的数组。
*/
splice(start: number, deleteCount: number, ...items: T[]): T[];
/**
* 在数组的开头插入新元素,并返回数组的新长度。
* @param items 要在数组开头插入的元素。
*/
unshift(...items: T[]): number;
/**
* 返回数组中第一个值的索引,如果不存在,则返回-1。
* @param searchElement 要在数组中定位的值。
* @param fromIndex 开始搜索的数组索引。如果省略fromIndex,搜索将从索引0开始。
*/
indexOf(searchElement: T, fromIndex?: number): number;
/**
* 返回指定值在数组中最后一次出现的索引,如果不存在,则返回-1。
* @param searchElement 要在数组中定位的值。
* @param fromIndex 开始向后搜索的数组索引。如果省略fromIndex,搜索将从数组中的最后一个索引开始。
*/
lastIndexOf(searchElement: T, fromIndex?: number): number;
/**
* 确定数组的所有成员是否满足指定的测试。
* @param predicate 最多接受三个参数的函数。every方法为数组中的每个元素调用谓词函数,直到谓词返回一个强制布尔值false的值,或者直到数组结束。
* @param thisArg 这个关键字在谓词函数中可以引用的对象。
* 如果省略thisArg,则使用undefined作为this值。
*/
every<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): this is S[];
/**
* 确定数组的所有成员是否满足指定的测试。
* @param predicate 最多接受三个参数的函数。every方法为数组中的每个元素调用谓词函数,直到谓词返回一个强制布尔值false的值,或者直到数组结束。
* @param thisArg 这个关键字在谓词函数中可以引用的对象。
* 如果省略thisArg,则使用undefined作为this值。
*/
every(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
/**
* 确定对于数组的任何元素,指定的回调函数是否返回true。
* @param predicate 最多接受三个参数的函数。一些方法调用
* 数组中每个元素的谓词函数,直到谓词返回一个强制布尔值true的值,或者直到数组结束。
* @param thisArg 这个关键字在谓词函数中可以引用的对象。
* 如果省略thisArg,则使用undefined作为this值。
*/
some(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
/**
* 为数组中的每个元素执行指定的操作。
* @param callbackfn 最多接受三个参数的函数。forEach为数组中的每个元素调用callbackfn函数一次。
* @param thisArg callbackfn函数中该关键字可以引用的对象。如果省略thisArg,则使用undefined作为this值。
*/
forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void;
/**
* 对数组的每个元素调用一个已定义的回调函数,并返回一个包含结果的数组。
* @param callbackfn 最多接受三个参数的函数。map方法为数组中的每个元素调用callbackfn函数一次。
* @param thisArg callbackfn函数中该关键字可以引用的对象。如果省略thisArg,则使用undefined作为this值。
*/
map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[];
/**
* 返回满足回调函数中指定条件的数组元素。
* @param predicate 最多接受三个参数的函数。filter方法为数组中的每个元素调用一次谓词函数。
* @param thisArg 这个关键字在谓词函数中可以引用的对象。如果省略thisArg,则使用undefined作为this值。
*/
filter<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[];
/**
* 返回满足回调函数中指定条件的数组元素。
* @param predicate 最多接受三个参数的函数。filter方法为数组中的每个元素调用一次谓词函数。
* @param thisArg 这个关键字在谓词函数中可以引用的对象。如果省略thisArg,则使用undefined作为this值。
*/
filter(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[];
/**
* 为数组中的所有元素调用指定的回调函数。回调函数的返回值是累积的结果,并在回调函数的下一次调用中作为参数提供。
* @param callbackfn 最多接受四个参数的函数。reduce方法为数组中的每个元素调用callbackfn函数一次。
* @param initialValue 如果指定了initialValue,它将用作开始累加的初始值。对callbackfn函数的第一次调用将该值作为参数而不是数组值提供。
*/
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
/**
* 为数组中的所有元素调用指定的回调函数。回调函数的返回值是累积的结果,并在回调函数的下一次调用中作为参数提供。
* @param callbackfn 最多接受四个参数的函数。reduce方法为数组中的每个元素调用callbackfn函数一次。
* @param initialValue 如果指定了initialValue,它将用作开始累加的初始值。对callbackfn函数的第一次调用将该值作为参数而不是数组值提供。
*/
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
/**
* 按降序为数组中的所有元素调用指定的回调函数。回调函数的返回值是累积的结果,并在回调函数的下一次调用中作为参数提供。
* @param callbackfn 最多接受四个参数的函数。reduceRight方法为数组中的每个元素调用callbackfn函数一次。
* @param initialValue 如果指定了initialValue,它将用作开始累加的初始值。对callbackfn函数的第一次调用将该值作为参数而不是数组值提供。
*/
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
/**
* 按降序为数组中的所有元素调用指定的回调函数。回调函数的返回值是累积的结果,并在回调函数的下一次调用中作为参数提供。
* @param callbackfn 最多接受四个参数的函数。reduceRight方法为数组中的每个元素调用callbackfn函数一次。
* @param initialValue 如果指定了initialValue,它将用作开始累加的初始值。对callbackfn函数的第一次调用将该值作为参数而不是数组值提供。
*/
reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
[n: number]: T;
}
interface ArrayConstructor {
new(arrayLength?: number): any[];
new <T>(arrayLength: number): T[];
new <T>(...items: T[]): T[];
(arrayLength?: number): any[];
<T>(arrayLength: number): T[];
<T>(...items: T[]): T[];
isArray(arg: any): arg is any[];
readonly prototype: any[];
}
declare var Array: ArrayConstructor;