OneBite.Dev - Coding blog in a bite size

remove a character from a string in Javascript

Code snippet on how to remove a character from a string in Javascript

  let newString = oldString.replace(characterToRemove, '');

This code takes an old string and a character that you would like to remove from the string and stores a new string in a variable named ‘newString’. This is done by using the method ‘.replace’, which will replace the first argument (the character to remove) with the second argument (an empty string in this case). The result will be a new string without the character you were trying to remove.

javascript