Javascript String toSlug()

Description

Javascript String toSlug()


String.prototype.toSlug = function() {

  var slug = this
    .toLowerCase()//  ww w  .j a v a  2 s.  c o m
    .replace(/[^\w ]+/g,'')
    .replace(/ +/g,'-')
  ;

  return slug;
}

Javascript String toSlug()

String.prototype.toSlug = function() {
  return this.match(/([\-a-zA-Z]+)/gi).join('-')
}



PreviousNext

Related