【发布时间】:2020-04-03 19:51:51
【问题描述】:
我在网上找不到同样的问题。 IE 11 给出错误“对象不支持属性或方法fill”。
var arr = new Array(5);
arr.fill(false);
是否有任何方便的方法来填充数组而不是使用for 循环?谢谢。
【问题讨论】:
标签: javascript
我在网上找不到同样的问题。 IE 11 给出错误“对象不支持属性或方法fill”。
var arr = new Array(5);
arr.fill(false);
是否有任何方便的方法来填充数组而不是使用for 循环?谢谢。
【问题讨论】:
标签: javascript
我面临同样的问题,不添加任何东西。
只需打开 polyfills.ts 文件并取消注释以下行:
/** 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';
一切都会开始工作。
【讨论】:
安装trivial polyfill 并继续使用.fill(…)。
【讨论】:
您可以使用Array.apply 获取具有所需长度的数组,然后将值映射到它。
var a = Array.apply(null, { length: 5 }).map(function () { return false; });
console.log(a);
【讨论】:
我遇到了同样的问题,需要取消注释 polyfill.ts 文件中的以下行,如下所示:
Polyfill.ts 文件路径:angular-App=> src=> polyfill.ts
打开此文件并取消注释以下行
/** 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';
现在它对我有用。
【讨论】:
填充();在 IE 中不支持。虽然它是在 EDGE 中引入的。我想 foreach 是完成任务的便捷方式。如果发现更多将更新。您可以阅读以下内容:
【讨论】:
添加以下脚本以将 pollyfill 从 CDN 下载到您的索引文件:
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default,Array.prototype.includes"></script>
这应该可行。
【讨论】:
const arr = Array.from(Array(10), () => 'none')
console.log(arr)
// ['none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none']
【讨论】: