当前位置:网站首页>Enum 枚举类型
Enum 枚举类型
2022-04-21 06:50:00 【小二李】
本篇文章将介绍TypeScript中枚举类型的相关使用。
定义枚举类型
enum Status {
OFFLINE,
ONLINE,
DELETED
}
使用枚举类型。
function getStatus(status) {
if (status === Status.OFFLINE) {
return 'offline'
} else if (status === Status.ONLINE) {
return 'online'
} else if (status === Status.DELETED) {
return 'deleted'
}
}
// 输出 deleted
console.log(getStatus(Status.DELETED))
输出枚举类型的值。
console.log(Status.OFFLINE)
console.log(Status.ONLINE)
console.log(Status.DELETED)

获取正向以及逆向枚举代表的值。
console.log(Status.OFFLINE,Status[0])

为枚举赋初始值。
enum Status {
OFFLINE = 1,
ONLINE,
DELETED
}
console.log(Status.OFFLINE,Status[0])
之所以Status[0]输出undefined,是因为我们为OFFLINE赋了初始值1,所以最小枚举索引值从1开始。

版权声明
本文为[小二李]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43800535/article/details/124288102
边栏推荐
- Dynamic generation of three-level menu
- Build openwrt file system for i.mx6q development board
- C# WebService 接口 通过Request请求获取json参数
- Axure产品原型工具使用笔记
- PHP Chinese to English initials
- php 无限极分类(递归)
- Introduction to btstack 1.0 of Bluetooth open source protocol stack
- Server deployment SVN environment
- php 输出两个指定日期中间的所有时间
- laravel实现打包多个文件,并下载
猜你喜欢

Flutter first experience

IIC bus design ① - IIC communication protocol

2022-04-20: the small regiment goes to participate in the military training. The military training is coming to an end. The officer wants to divide n people in a row into m groups, and then ask each g

leetcode 59. Spiral matrix II

PLSQL developer 14 installation details

Record the problems and solutions encountered in using fastjson message converter

《Qt 5.12实战》简介

【第31题】创造两只完全相同的宠物

Hackmyvm integrated target | driftingblues-9 (end)

leetcode题目--120.三角形最小长度和,简单dp
随机推荐
Flutter environment construction and other foundations
Flutter first experience
asp.net js 实现动态添加文件上传
OmniPlan工具使用手册
PostgreSQL 15 will soon support merge statements in the SQL standard
php base64加密
Implementation and application of STM32 system and custom bootloader
IIC总线设计①——IIC通信协议
.net core 将错误抛出写入.txt文件
Regular Expressions
PHP removes commas at the beginning or end of strings
Record the problems and solutions encountered in using fastjson message converter
Relationship between application software threads and CPU cores
Annotation function supplement
三级菜单动态生成
Flutter初体验
asp. Net JS to realize dynamic addition and file upload
C WebService interface obtains JSON parameters through request
基于JeecgBoot的v-has权限控制
Leetcode topic -- 120 Minimum length sum of triangles, simple DP