Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

create slug in javascript

function makeSlug(slug){
  let finalSlug = slug.replace(/[^a-zA-Z0-9]/g, ' ');
  //remove multiple space to single
  finalSlug = slug.replace(/  +/g, ' ');
  // remove all white spaces single or multiple spaces
  finalSlug = slug.replace(/s/g, '-').toLowerCase().replace(/[^w-]+/g, '-');
  return finalSlug;
}

//example of work 
let slug = makeSlug('What Is a CSS Framework? (And When to Use 6 Popular Options)           ') 

console.log(slug) // what-is-a-css-framework---and-when-to-use-6-popular-options------------
 
PREVIOUS NEXT
Tagged: #create #slug #javascript
ADD COMMENT
Topic
Name
9+1 =