javascript - IE 11 的 Map(iterable) 替代方案

标签 javascript typescript internet-explorer internet-explorer-11 polyfills

不幸的是我必须支持 IE11。

我使用此代码创建我的 map (已使用 .entries 的 polyfill):

const map = new Map(Object.entries(array));

但由于 IE11 不支持 iterable 构造函数,Map 为空。

我找不到 polyfill 或其他任何东西。谁有解决此问题的简单方法?

然后我像这样使用 map:

  map.forEach((maps: ITopoInterface[], key: string) => {
    maps.findIndex((t: ITopoInterface) => {
     //do stuff
    });
  });

最佳答案

你说这是空的:

const map = new Map(Object.entries(array));

您是否尝试过自己添加值?

const map = new Map();
Object.entries(array).forEach(entry => {
    map.set(entry[0], entry[1]);
});

关于javascript - IE 11 的 Map(iterable) 替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59375015/

相关文章:

javascript - 使用正则表达式从函数中删除参数类型

Javascript IRR(内部 yield )公式准确性

typescript - 接口(interface)属性上的类型缩小(删除空选项)

javascript - Polyfill 支持 Angular 9 自定义元素?

javascript - document.elementFromPoint 在 IE 上返回 null

javascript - Mongoose 使用 $in 并且只用最近的时间戳更新一个

angular - Ionic 4每次进入都会刷新标签页

html - 卢比符号图像在 IE 8,9 中不可见

javascript - IE9中的History.pushState添加Hash标签

javascript - 如何禁用文本输入的正常提交输入行为并将其替换为我自己的功能?