javascript delete all occurrences of a char in a string

Regular expressions [xkcd] (I feel like him ;)):

s = s.replace(/[\[\]&]+/g, '');

Reference:

  • MDN – string.replace
  • MDN – Regular Expressions
  • http://www.regular-expressions.info/

Side note:

JavaScript’s replace function only replaces the first occurrence of a character. So even your code would not have replaced all the characters, only the first one of each. If you want to replace all occurrences, you have to use a regular expression with the global modifier.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)