Javascript String camelize(index)

Description

Javascript String camelize(index)


String.prototype.camelize = function(index)
{
  var parts = this.split(/[-_]/);
  var str = '';
  if (typeof index == 'undefined') {
    index = 1;//from ww w.jav a2s .c  o m
  }
  for (var i=0; i<index; i++) {
    str += parts[i];
  }
  for (var i=index; i<parts.length; i++)
  {
    str += parts[i].substr(0, 1).toUpperCase();
    str += parts[i].substr(1);
  }
  return str;
}



PreviousNext

Related