TypeScript 数组Array操作的常用方法

时间:2025-01-25 19:09:51

/**

  * Combines two or more arrays.

  * @param items Additional items to add to the end of array1.

  */

concat(...items: T[][]): T[];

/**

  * Combines two or more arrays.

  * @param items Additional items to add to the end of array1.

  */

concat(...items: (T | T[])[]): T[];

/**

 * 该方法返回指定起始位置的一个新的数组

 */

slice(start?: number, end?: number): T[];

let array: Array<number> = [1, 2, 3];

let array2: Array<number> = [4, 5, 6];

let arrayValue = 7;

array = ( array2);

(array)          // [1, 2, 3, 4, 5, 6]

array = (arrayValue);

(array)          // [1, 2, 3, 4, 5, 6, 7]

let newArray = (2, 4);

(newArray)      // [3, 4]