How to remove all occurrences of char from string

Let's see an example on how to delete a certain character from a string (remove all occurrences):

// Declaring the string
let string = 'oHi, omy noame ios Eroik!';

// Declaring the character to remove
let charToRemove = 'o';

// Getting the new string:
// 1. Transforming string into array [...string]
// 2. Filtering characters which are different from charToRemove
// 3. Transforming array to string with join()
string = [...string].filter(character => character !== charToRemove).join('');

// 'Hi, my name is Erik!'

Since JavaScript replace() function doesn't replace all occurrences, this is a way to do it.

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.