-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: JavaScript
-
None
-
Fully Compatible
-
Build 7 08/10/15
The implementation of String.endsWith() needlessly uses regexps:
String.prototype.endsWith = function(str){ return new RegExp(RegExp.escape(str) + "$").test(this) }
Safer and almost certainly faster is to use indexOf() to just directly check the end of the string:
String.prototype.endsWith = function(suffix) { return this.indexOf(suffix, this.length - suffix.length) !== -1; };
- is related to
-
SERVER-19369 Add String.includes() polyfill
- Closed