Fork me on GitHub

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

js驼峰写法转短横线格式

  1. 小写字母转大写

    var UP = function(s){
      return s.toUpperCase().split(' ').join('_')
    }
    
    UP('Hedge number')
    
  2. 将格式为 CONTRACT_NUM 转换为驼峰形式

    var upFirst = function(s){
    //   首字母大写
      var arrs = s.split('')
      arrs[0] = arrs[0].toUpperCase()
      return arrs.join('')
    }
    var D = function(s){
      var arr = s.toLowerCase().split('_')
      arr = arr.map(function(item,index){
        return index !== 0 ? upFirst(item) : item
      })
      return arr.join('')
    }
    
    D('CONTRACT_NUM')
    
  3. 删除对象属性

    var obj = { name : 'xxx'}
    delete obj.name
    console.log(obj.name)  //undefined
    
posted @ 2020-10-18 15:47  365/24/60  阅读(621)  评论(0编辑  收藏  举报