Map(iterable) alternative for IE 11

元气小坏坏 提交于 2020-05-27 12:41:05

问题


Unfortunately I have to support IE11.

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

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

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

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

Afterwards I use the map like this:

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

回答1:


You say this is empty:

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]);
});


来源:https://stackoverflow.com/questions/59375015/mapiterable-alternative-for-ie-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!