Javascript .includes() not working in IE

includes() is part of the ES6 specification, so it's not supported in IE. What you can use instead is indexOf(element) !== -1


replace:

if(field.toLowerCase().includes(key)) {

to:

if(field.toLowerCase().indexOf(key) > -1) {

For your reference, Mozilla Developer Network shows which browsers support String.prototype.includes.

IE does not have any support. That being said, you can always polyfill it, or do as others have specified and use String.prototype.indexOf.

Polyfill src: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes#Polyfill

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;
    }
  };
}

Tags:

Javascript