TypeScript Record 特性
TypeScript About 378 words说明
类似于JavaScript中的Map。
与Map不同的是:
Record遍历时先输出数字类型的字段,再输出字符类型的字段Map遍历时按放入时的顺序输出。
Record<string, MyData[]>
自定义类型
interface MyData {
category: string,
amount: number
}
等价于
interface GroupType {
[key: string]: MyData[];
}
遍历 Record
使用Object.entries遍历Record对象,map映射为[]数组,数组中第0个元素是key,第1个元素是key对应的value。
Object.entries(xxx).map(([key, object]) => {
return yyy;
})
Views: 155 · Posted: 2025-10-07
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...