Skip to content

数组和元组

js
// 数组
let arrNums: (number | string)[] = [0, '1']

let objArr: {name: string, age: number}[] = [{name: 'tom', age: 18}]

// type 类型别名
type User = {name: string, age: number}
let objArr1: User[] = [{name: 'tom', age: 18}]


// 元组 tuple【强制约束数组中的元素类型和长度】
let testInfo: [number, string] = [0, '1']
// 进阶元组
let userList: [string, number][] = [
    ['tom', 19],
    ['chaos', 18]
]