“Slug Generator JavaScript” Kode Jawaban

Slug Generator JavaScript

var slug = "CodePadding Rahman     ( Mizan ) 12456 <> title";
slug = slug.toLowerCase().replace(/[^\w-]+/g, '-');
console.log(slug); // codepadding-rahman-mizan-12456-title
CodePadding

Slug Generator JavaScript

var slug = "CodePadding Rahman     ( Mizan ) 12456 <> title";
//change all characters except numbers and letters
slug = slug.replace(/[^a-zA-Z0-9]/g, ' ');
//remove multiple space to single
slug = slug.replace(/  +/g, ' ');
// remove all white spaces single or multiple spaces
slug = slug.replace(/\s/g, '_').toLowerCase();
console.log(slug)
// output - codepadding_rahman_mizan_12456_title
CodePadding

Jawaban yang mirip dengan “Slug Generator JavaScript”

Pertanyaan yang mirip dengan “Slug Generator JavaScript”

Lebih banyak jawaban terkait untuk “Slug Generator JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya