我是靠谱客的博主 认真衬衫,这篇文章主要介绍《学习笔记8》——toUpperCase、toLowerCase、toLocaleUpperCase、toLocaleLowerCase的使用,现在分享给大家,希望可以做个参考。
1.toUpperCase()方法
toUpperCase() 方法用于把字符串转换为大写。
let str1 = 'abc';
console.log(str1.toUpperCase());
上述代码的输出如下:
ABC
注意,该方法改变了原始字符串。
2.toLowerCase()方法
toLowerCase() 方法用于把字符串转换为小写。因为用法和toUpperCase() 方法一致,所以这里不作过多的解释。
3.toLocaleUpperCase()方法
toLocaleUpperCase()方法用于根据本地主机的语言环境把字符串转换为大写。本地是根据浏览器的语言设置来判断的。
let str1 = 'abc';
let str2 = str1.toLocaleUpperCase();
console.log(str2);
上述代码的输出如下:
ABC
该方法的输出结果和toUpperCase()方法的输出结果一致,但不一样的是,toLocaleUpperCase()方法没有改变原始字符串。
4.toLocaleLowerCase()方法
toLocaleLowerCase() 方法根据本地主机的语言环境把字符串转换为小写。用法和toUpperCase()方法一致。
最后
以上就是认真衬衫最近收集整理的关于《学习笔记8》——toUpperCase、toLowerCase、toLocaleUpperCase、toLocaleLowerCase的使用的全部内容,更多相关《学习笔记8》——toUpperCase、toLowerCase、toLocaleUpperCase、toLocaleLowerCase内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复