首页 文章资讯内容详情

JavaScript判断字符串中的字母是大写还是小写

2026-06-03 1 花语

要使用javascript测试字符串中的字母是大写还是小写,只需将字符转换为相应的大小写,然后查看结果。

示例

function checkCase(ch) { if (!isNaN(ch * 1)){ return ch is numeric; } else { if (ch == ch.toUpperCase()) { return upper case; } if (ch == ch.toLowerCase()){ return lower case; } } } console.log(checkCase(a)) console.log(checkCase(A)) console.log(checkCase(1))

输出结果

lower case upper case ch is numeric