元组

let tom: [string, number] = ['lx', 29];
tom[0] = 'haha';
tom[1] = 22;
tom = ['nice', 18];
tom.push(2);
tom.push(true); //当添加越界的元素时,它的类型会被限制为元组中每个类型的联合类型

数组合并了相同类型的对象,而元组(Tuple)合并了不同类型的对象。

 

posted @ 2020-12-13 14:08  小翔momo  阅读(66)  评论(0编辑  收藏  举报