Hello, I was doing a function that removes all the vowels from a string, it works fine for me when I do it for a letter... like this:
function eliminarVocal(str) {
var resultado = str.replace(/a/g, '');
return resultado
}
If I do multiple .replace(/vocal/g, '') it would work for me but I was thinking of something more optimal, to remove all the letters specified in an array or something like that and it doesn't work for me. How could I do it? Thanks
You were very close, although you don't need an array, with a simple regular expression you solve it, be careful only with those that don't have accents for this example.
This simple regular expression
[aeiou]
set to global, combined with the functionreplace
finds all the characters indicated in the square brackets and replaces them with an empty character.To use it with all vowels including accented ones, capital letters;