Javascript String toUnderscore() method

Description

Javascript String toUnderscore() method


String.prototype.toUnderscore = function(){
  return this.replace(/([A-Z])/g, function($1){return "_"+$1.toLowerCase();});
};

Javascript String toUnderscore()

String.prototype.toUnderscore = function(){
  return this.charAt(0).toLowerCase() + this.substring(1).replace(/([A-Z])/g, function($1){return "_"+$1.toLowerCase();});
};
console.log(process.argv[2].toUnderscore());

Javascript String toUnderscore()

String.prototype.toUnderscore = function(){
 return this.replace(/([A-Z])/g, function($1){return "_"+$1.toLowerCase();});
};

var names = [//from   www . ja  va 2 s. co  m
  "fieldName01",
  "fieldName02",
];

names.forEach(function(element) {
  console.log(element.toUnderscore());
});

Javascript String toUnderscore()

String.prototype.toUnderscore = function() {
  return this.replace(/(^[A-Z])/, function(match) {
    return match.toLowerCase();
  }).replace(/([A-Z])/g, function(match){
    return "_" + match.toLowerCase();
  });/*  w  w w . j  a  v a 2 s  . co  m*/
};

Javascript String toUnderscore()

String.prototype.toUnderscore = function(){
 return this.replace(/([A-Z])/g, function($1){return "_"+$1.toLowerCase();});
};

Javascript String toUnderscore()

String.prototype.toUnderscore = function() {
  var str = this.replace(/[A-Z]/g, function(s) {
    return "_" + s.toLowerCase();
  });/*from  w  w w  .  j  a v a2  s  .c o m*/
  while (str.charAt(0) === '_') {
    str = str.slice(1);
  }
  return str;
};

Javascript String toUnderscore()

/**//from   w  w  w  . ja v  a 2s. c  o m
  * toUnderscore()
  * -------------------------
  * @desc: converts string from camel case to underscore format
  * @type: (string)
*/
String.prototype.toUnderscore = function(){
 return this.replace(/([A-Z])/g, function($1){return "_"+$1.toLowerCase();});
};



PreviousNext

Related