Javascript/jQuery: Split camelcase string and add hyphen rather than space

前端 未结 5 1248
故里飘歌
故里飘歌 2020-12-23 11:29

I would imagine this is a multiple part situation with regex, but how would you split a camelcase string at the capital letters turning them in to lowercase letters, and the

5条回答
  •  攒了一身酷
    2020-12-23 12:03

    String.prototype.camelCaseToDashed = function(){
      return this.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
    }
    // Usage
    "SomeVariable".camelCaseToDashed();
    

提交回复
热议问题