IE 11的Map(iterable)替代方案 [英] Map(iterable) alternative for IE 11

查看:151
本文介绍了IE 11的Map(iterable)替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,我必须支持IE11.

Unfortunately I have to support IE11.

我用以下代码创建地图(已经使用了.entries的polyfill)

I create my map with this code (polyfill for .entries already used):

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

,但是由于IE11不支持 iterable 构造函数,因此Map为空.

but because of IE11 not supporting the iterable constructor the Map is empty.

我找不到用于此的polyfill或其他任何东西.有人有简单的方法解决此问题吗?

I couldn't find a polyfill or anything else for this. Does anyone have an easy way of fixing this?

然后我像这样使用map:

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

推荐答案

您说的是空的:

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

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

Have you tried just adding the values yourself?

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

这篇关于IE 11的Map(iterable)替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆