13

I cannot find same problem online. IE 11 gives error "Object doesn't support property or method fill".

var arr = new Array(5);
arr.fill(false);

Is there any convenient way to to fill an array instead of using a for loop? Thanks.

6324
  • 4,678
  • 8
  • 34
  • 63

7 Answers7

22

I face the same issue, not to add anything.

Just open polyfills.ts file and un-comment following lines:

/** 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';

Every thing will start working.

Ali Adravi
  • 21,707
  • 9
  • 87
  • 85
13

Install the trivial polyfill and continue using .fill(…).

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • 1
    This should be the correct answer. Don't agonize about whether or not your favorite method is available - just provide a polyfill in case it isn't. – Tad Donaghe Jun 09 '16 at 14:56
1

You could use Array.apply for getting an array with the wanted length and then map the value to it.

var a = Array.apply(null, { length: 5 }).map(function () { return false; });
console.log(a);
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392
1

I have face same issue and need to uncomment following lines in polyfill.ts file as follows:

Polyfill.ts file path: angular-App=> src=> polyfill.ts

Open this file and uncomment following lines

/** 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';

Now it's work for me.

Manoj Gupta
  • 456
  • 4
  • 9
0

fill(); Does not support in IE. It is introduced in EDGE though. I guess foreach is the convenient way to do the task. Will update if find more. You can read the following :

Community
  • 1
  • 1
Sagiruddin Mondal
  • 5,407
  • 2
  • 29
  • 44
0

Add below script to download pollyfill from CDN to your index file:

<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default,Array.prototype.includes"></script>

This should work.

Shubham
  • 187
  • 1
  • 2
  • 15
0

const arr = Array.from(Array(10), () => 'none')
console.log(arr)
// ['none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none']
Khanh Lam
  • 11
  • 3