switch (contentType) { case "text" -> { return 1; } case "image" -> { return 2; } case "audio" -> { return 3; } case "video" -> { return 4; } default -> { return 5; } }将这段代码转换成JavaScript的
时间: 2023-06-06 07:06:29 浏览: 95
代码如下:
```
switch (contentType) {
case "text":
return 1;
case "image":
return 2;
case "audio":
return 3;
case "video":
return 4;
default:
return 5;
}
```
相关问题
将这段代码转换为js:private int contentTypeIdentification(String contentType) { if (StringUtils.isEmpty(contentType)) { return 5; } else { final int i = contentType.indexOf('/'); if (i != -1) { contentType = contentType.substring(0, i); } switch (contentType) { case "text" -> { return 1; } case "image" -> { return 2; } case "audio" -> { return 3; } case "video" -> { return 4; } default -> { return 5; } } } }
function contentTypeIdentification(contentType) {
if (contentType.length == 0 || contentType === null || contentType === undefined) {
return 5;
} else {
const i = contentType.indexOf('/');
if (i != -1) {
contentType = contentType.substring(0, i);
}
switch (contentType) {
case "text":
return 1;
case "image":
return 2;
case "audio":
return 3;
case "video":
return 4;
default:
return 5;
}
}
}
阅读全文