typescript 怎么遍历object

typescript 怎么遍历object


慕虎7371278
浏览 5425回答 2
2回答

幕布斯6054654

与其问typescript怎么遍历object 还不如问javascript怎么遍历object,作为javascript的超集,用typescript写的东西完全可以在javascript里运行,typescript里边也可以使用javascript的语法。回答你的问题你需要明白JavaScript怎么遍历Object的,也就是你问的题干的答案。你可以这样理解超集含义,typescript本身没有Object这个类型,或者typescript里边的object类型跟javascript的一样

九州编程

123456789101112131415161718interface&nbsp;People&nbsp;{readonly&nbsp;name:&nbsp;stringreadonly&nbsp;age:&nbsp;number}const&nbsp;people:&nbsp;People&nbsp;=&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;name:&nbsp;'tom',&nbsp;&nbsp;&nbsp;&nbsp;age:&nbsp;16}for(let&nbsp;key&nbsp;in&nbsp;people){console.log(key)}const&nbsp;people2:&nbsp;ReadonlyArray<People>&nbsp;=&nbsp;[{&nbsp;name:&nbsp;'tom',&nbsp;age:&nbsp;14&nbsp;}]//遍历数组类型for(let&nbsp;key&nbsp;of&nbsp;people2){}for(let&nbsp;key&nbsp;in&nbsp;people2){}people2.forEach((data:&nbsp;People)&nbsp;=>&nbsp;console.log(data))&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript