Javascript String hyphenize()

Description

Javascript String hyphenize()

String.prototype.hyphenize = function()
{
  var parts = this.split(/([A-Z].+)/);
  var str = '';
  for (var i=0; i<parts.length; i++)
  {/*w  w w  .j  a  v a 2  s  .com*/
    if (parts[i] != '') {
      str += parts[i].toLowerCase() + '-';
    }
  }
  return str.replace(/[-]+$/, '');
}



PreviousNext

Related