zoukankan      html  css  js  c++  java
  • 字符串转化成驼峰命名

        function convertToCamelCase (str) {
            var returnStr;
            if (str.charAt(0) === '-') {
                returnStr = str.substring(1).split('-')
            } else {
                returnStr = str.split('-')
            }
            console.log(returnStr)
            for (var i = 1; i<returnStr.length; i++) {
                returnStr[i] = returnStr[i][0].toUpperCase() + returnStr[i].substring(1)
            }
            return returnStr.join('')
        }
        console.log(convertToCamelCase('background-img-img2'))
    

      方法二:

        function convertToCamelCase (str) {
            var returnStr = str.split('-');
            if (returnStr[0] === '') {
                returnStr.shift()
            }
            for (var i = 1; i<returnStr.length; i++) {
               if (returnStr[i] !== '') {
                   returnStr[i] = returnStr[i][0].toUpperCase() + returnStr[i].substring(1)
               }
            }
            return returnStr.join('')
        }
        console.log(convertToCamelCase('-background-img-cas'))
    

      

  • 相关阅读:
    VIM配置
    VSCode配置Import@路径
    Sar
    VIM-Fold折叠
    sysctl
    java8 到 java14新增的特性
    Electron整合VUE
    使用Markfile开发GO程序
    cron 表达式
    java spi
  • 原文地址:https://www.cnblogs.com/ly-qingqiu/p/12157430.html
Copyright © 2011-2022 走看看