代码之家  ›  专栏  ›  技术社区  ›  6324

对象不支持属性或方法“fill”

  •  13
  • 6324  · 技术社区  · 10 年前

    我在网上找不到同样的问题。IE 11给出错误“对象不支持属性或方法 fill ".

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

    有什么方便的方法来填充数组而不是使用 for 环谢谢

    7 回复  |  直到 7 年前
        1
  •  22
  •   Ali Adravi    7 年前

    我面临同样的问题,不想补充任何内容。

    只需打开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';
    

    一切都会开始运作。

        2
  •  13
  •   Bergi    10 年前

    安装 trivial polyfill 并继续使用 .fill(…) .

        3
  •  1
  •   Nina Scholz    10 年前

    你可以用 Array 应用以获取具有所需长度的数组,然后将值映射到该数组。

    var a = Array.apply(null, { length: 5 }).map(function () { return false; });
    console.log(a);
        4
  •  1
  •   Manoj Gupta    7 年前

    我也面临同样的问题,需要在polyfill中取消注释以下行。ts文件如下:

    Polyfill公司。ts文件路径:angle App=>src=>聚合.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';
    

    现在是我的工作。

        5
  •  0
  •   Community Mohan Dere    9 年前

    填充();不支持IE。但EDGE引入了它。我想每个人都是完成任务的方便方式。如果找到更多,将更新。您可以阅读以下内容:

        6
  •  0
  •   Shubham    8 年前

    添加以下脚本以将pollyfill从CDN下载到索引文件:

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

    这应该行得通。

        7
  •  0
  •   Khanh Lam    6 年前

    const arr = Array.from(Array(10), () => 'none')
    console.log(arr)
    // ['none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none']