Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internet Explorer 11 - Object doesn't support property or method 'includes'

I'm getting this error in IE 11, on all other common browsers it works fine.

I use this code which makes use of 'includes':

const keys = Object.keys(this.service.content);

            if (keys.includes(splitUrl[splitUrl.length - 1])) {
                this.router.navigateByUrl(`/mysite/${splitUrl[splitUrl.length - 1]}/1`);
            }

Any alternatives?

like image 333
bobdolan Avatar asked Apr 18 '18 10:04

bobdolan


3 Answers

I was Face same Problem with Angular 7.0+ and IE11

I got solution by adding one line to my polyfill.ts file.

import 'core-js/es7/array';

I get this solution from this article Internet Explorer 11 and Angular 2+

NB: If you want to avoid this kind of situation for IE browser then you should read this article Thanks to Maarten Merken.

like image 96
MD Ashik Avatar answered Nov 08 '22 21:11

MD Ashik


If anyone is looking for ReactJS solution -

Used import 'core-js/es6/string'; at the start of index.js to solve my problem.

I'm also using import 'react-app-polyfill/ie11'; to support running React in IE11.

react-app-polyfill

This package includes polyfills for various browsers. It includes minimum requirements and commonly used language features used by Create React App projects.

https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md

like image 41
BeeBee8 Avatar answered Nov 08 '22 20:11

BeeBee8


If you are using angular/cli, open up polyfills.ts file and uncomment the required polyfill.

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
// import 'core-js/es6/symbol';
// import 'core-js/es6/object';
// import 'core-js/es6/function';
// import 'core-js/es6/parse-int';
// import 'core-js/es6/parse-float';
// import 'core-js/es6/number';
// import 'core-js/es6/math';
// import 'core-js/es6/string';
// import 'core-js/es6/date';
import 'core-js/es6/array';
// import 'core-js/es6/regexp';
// import 'core-js/es6/map';
// import 'core-js/es6/weak-map';
// import 'core-js/es6/set';

You might also want to include other polyfills required by IE11.

like image 3
Tomasz Kula Avatar answered Nov 08 '22 21:11

Tomasz Kula