# 数组
# 数组解构
代码语言:javascript复制let x: number;
let y: number;
let z: number;
let five_array = [0, 1, 2, 3, 4];
[x, y, z] = five_array;
console.log(x, y, z); // 0 1 2
# 数组展开运算符
代码语言:javascript复制let two_array = [0, 1];
let five_array = [...two_array, 2, 3, 4];
console.log(five_array); // [0, 1, 2, 3, 4]
# 数组遍历
代码语言:javascript复制let colors: string[] = ["red", "green", "blue"];
for (let color of colors) {
console.log(color);
}
# 对象
# 对象解构
代码语言:javascript复制let person = {
name: "Cell",
gender: 'Male',
};
let { name, gender } = person;
# 对象展开运算符
代码语言:javascript复制let person = {
name: "Cell",
gender: "Male",
address: "Earth",
};
// 组装对象
let person2 = { ...person, age: 18 };
// 获取除了某些项外的其他项
let { name, ...rest } = person;