I have been working on a project and developing a JavaScript framework. The original code is about 700 lines so I only pasted this line. The includes method doesn't work on Internet Explorer. Is there any solution for this?
var row_cells = tbl_row.match(/<td[\s\S]*?<\/td>/g); row.Cells = new Array(); if (onRowBindFuncText != null) { /*Fonksyon tanımlanmaışsa daha hızlı çalış*/ var cellCount = 0; for (i = 0; i < row_cells.length; i++) { var cell = new Cell(); $.each(this, function (k, v) { if ((row_cells[i]+"").includes("#Eval(" + k + ")")) { cell.Keys.push(new Key(k,v));
...Code goes on
includes was not supported in IE. I had to write substitute of this function. This function basically did 2 things: check if element is in array.
indexOf() The Array#indexOf() function is a common alternative to includes() . The indexOf() function returns the first index in the array at which it found valueToFind , or -1 otherwise.
Because it's not supported in IE, it is not supported also in Opera (see the compatibility table), but you can use the suggested polyfill:
Polyfill
This method has been added to the ECMAScript 2015 specification and may not be available in all JavaScript implementations yet. However, you can easily polyfill this method:
if (!String.prototype.includes) { String.prototype.includes = function(search, start) { 'use strict'; if (typeof start !== 'number') { start = 0; } if (start + search.length > this.length) { return false; } else { return this.indexOf(search, start) !== -1; } }; }
@Infer-on shown great answer, but it has a problem in a specific situation. If you use for-in loop it will return includes "includes" function you added.
Here is another pollyfill.
if (!Array.prototype.includes) { Object.defineProperty(Array.prototype, "includes", { enumerable: false, value: function(obj) { var newArr = this.filter(function(el) { return el == obj; }); return newArr.length > 0; } }); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With