Here you can find the source of filter(func)
String.prototype.filter = function(func) { str = this.split(""); var ans = [];//from w w w . j a v a 2s . c o m str.forEach(function(x) { if (func(x)) { ans.push(x); }; }); return ans; };
String.prototype.filter = function(f) { return this.split("").filter(f).join(""); };