
编写一个函数,将单个camelcase格式的字符串转换为snake_case格式的字符串。
吉卜力风格图片在线生成
将图片转换为吉卜力艺术风格的作品
121 查看详情
解决方案
// a function cameltocase that takes a string (text) as the parameter.function cameltocase(text) { // transform each uppercase letter (character) based on its position. function uppertounderscorelower(character, position) { // if the letter isn't the first character, add an underscore and convert it to lowercase. return (position > 0 && "_") + match.tolowercase(); } // replace all uppercase letters in (text) by calling the uppertounderscorelower function. return text.replace(/[a-z]/g, uppertounderscorelower);}console.log(cameltocase("cameltocase"));
结果
> camel_to_case
以上就是在JavaScript中将camelToCase转换为snake_case的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/439004.html
微信扫一扫
支付宝扫一扫