本文介绍了Typescript枚举值作为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 是否可以将TypeScript中的枚举值作为数组获取? 像这样: 枚举MyEnum { FOO ='foo', BAR ='bar'} 成为 ['foo','bar'] 解决方案是的,可以使用: Object.values(MyEnum) 因为编译后枚举是JS对象: var MyEnum; (函数(MyEnum){ MyEnum [ FOO] = foo; MyEnum [ BAR] = bar; })(MyEnum || (MyEnum = {})); Is it possible to get the values of an enum in TypeScript as an array?Like this:enum MyEnum { FOO = 'foo', BAR = 'bar'}becomes['foo', 'bar'] 解决方案 Yes, it is possible to use:Object.values(MyEnum)because enum is an JS object after compilation:var MyEnum;(function (MyEnum) { MyEnum["FOO"] = "foo"; MyEnum["BAR"] = "bar";})(MyEnum || (MyEnum = {})); 这篇关于Typescript枚举值作为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-14 06:07