Code not running in IE 11, works fine in Chrome Code not running in IE 11, works fine in Chrome javascript javascript

Code not running in IE 11, works fine in Chrome


String.prototype.startsWith is a standard method in the most recent version of JavaScript, ES6.

Looking at the compatibility table below, we can see that it is supported on all current major platforms, except versions of Internet Explorer.

╔═══════════════╦════════╦═════════╦═══════╦═══════════════════╦═══════╦════════╗║    Feature    ║ Chrome ║ Firefox ║ Edge  ║ Internet Explorer ║ Opera ║ Safari ║╠═══════════════╬════════╬═════════╬═══════╬═══════════════════╬═══════╬════════╣║ Basic Support ║    41+ ║     17+ ║ (Yes) ║ No Support        ║    28 ║      9 ║╚═══════════════╩════════╩═════════╩═══════╩═══════════════════╩═══════╩════════╝

You'll need to implement .startsWith yourself. Here is the polyfill:

if (!String.prototype.startsWith) {  String.prototype.startsWith = function(searchString, position) {    position = position || 0;    return this.indexOf(searchString, position) === position;  };}


text.indexOf("newString") is the best method instead of startsWith.

Example:

var text = "Format";if(text.indexOf("Format") == 0) {    alert(text + " = Format");} else {    alert(text + " != Format");}


If this is happening in Angular 2+ application, you can just uncomment string polyfills in polyfills.ts:

import 'core-js/es6/string';