js中的”类数组”类型
1.arguments
function test() {
console.log(arguments);
console.log(arguments.length);
}
2.HTMLAllCollection
let htmlCollection: HTMLAllCollection;
3.others…
数组
let arrOfNumbers: number[] = [1, 2, 3];
arrOfNumbers.push(5);
元祖(tuple)
元祖的定义
let user: [name: string, age: number] = ["Felix", 18];
let player: [string, number] = ["Felix", 18];
元祖的本质
元祖的本质其实就是数组, 只是约束了每一个元素的类型而已, 元素的类型不是全部一样, 如果全部一样的话, 那就是数组了
let user: [name: string, age: number] = ["Felix", 18];
let player: [string, number] = ["Felix", 18];
player.push("Chan");
console.log("player", player);
(只能push元祖包含的类型, string和number)
输出结果
约束数组里面的值的类型有2种写法
let a: string[] = ["a", "b", "c"];
let b: Array<string> = ["a", "b", "c"];
// 这种写法是约束这个数组里面只有一个元素, 并且这个元素是string
let c: [string] = ["a"];