i was trying to make a function that can take a char and a string as arguments and remove that char from the string.
function removeCharacter(char, str) {
return str.replace(char, '');
}
ex: removeCharacter('r', "character") - > chaacte
Doing this way only removes the first char so I found out about the global Regex, but here is where I hit a wall...how can I make it so it can take any given char something like:
str.replace(/char/g, '')
I want pass that char as an argument in the function and remove all of them. Is there a way to this with regex or should i use a for statement? Or is there a better way?