Javascript String toUnderscore()
method
String.prototype.toUnderscore = function(){ return this.replace(/([A-Z])/g, function($1){return "_"+$1.toLowerCase();}); };
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());
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()); });
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*/ };
String.prototype.toUnderscore = function(){ return this.replace(/([A-Z])/g, function($1){return "_"+$1.toLowerCase();}); };
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; };
/**//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();}); };