How to remove accent marks in a string using vanilla JavaScript

In JS is quite of easy to replace chars by using str.replace for example, but, what happens when you want to remove accent marks?

This tiny post will build an example on how to make a slug from a Spanish sentence.

// Input example
const spanishSentences = [
  "Mandó una carta",
  "Qué grande es ese perro"

// Function definition
function createSlug(input){
  return input
    .replace(/[\s_-]+/g, "-")
    .replace(/^-+|-+$/g, "")
    .replace(/[\u0300-\u036f]/g, "");

// Usage
const output =;
// Output:
// ["telefono", "arbol", "colibri", "compramelo", "mando-una-carta", "que-grande-es-ese-perro"]

You can see this example working here

Happy Coding! :)