Remove all of the characters of a given string from a string - Node.js String

Node.js examples for String:Char

Description

Remove all of the characters of a given string from a string

Demo Code

/* Remove all of the characters of a given string from a string
 *
 * "Abracadabra".removechars('ar')  // => "Abcdb"
 *///from  w w  w  .j  av  a 2s. c  o  m
String.prototype.removechars = function ( chars ) {
  if ( arguments.length > 1 ) {
    chars = Array.prototype.join.call( arguments, '' );
  }
  var rx = RegExp.compile('['+RegExp.escape(chars)+']', 'g');
  return this.replace( rx, '' );
};

Related Tutorials