What is the alternative for find in IE? Im getting this error TypeError: Object doesn't support property or method 'find'

What is the alternative for find in IE? Im getting this error TypeError: Object doesn't support property or method 'find'

我在代码中使用 'find'

var route = Object.keys(Routes).find(matchingLang)

IE不支持。在 chrome 和 firefox 它工作 fine.In IE ,它抛出这个错误 TypeError: Object doesn't support property or method 'find'

这是我的代码

 var browLoc="en-GB"

    var Routes ={
                'en-*':'en_US',
                'es-*':'es_ES', 
                'pt-*':'pt_PT',
                'fr-*':'fr_FR',
                'de-*':'de_DE',
                'ja-*':'ja_JP',
                'it-*':'it_IT',
                 '*':'en_US'    
            }; 

    var matchingLang = function (route) {return new RegExp('^' + route.replace('*', '.*')).test(browLoc) }                          

    var route = Object.keys(Routes).find(matchingLang);

如果我使用 'filter' 代替 find ,它将 returns 所有匹配值。我只想要一个输出,即只有一个语言值。

如果有人知道任何替代方法,请做 help.Thanks

如前所述,IE 不支持 find()。不知道为什么你需要让它变得那么复杂。只需拆分并添加 -* 即可。

var browLoc="en-GB"

var Routes ={
            'en-*':'en_US',
            'es-*':'es_ES', 
            'pt-*':'pt_PT',
            'fr-*':'fr_FR',
            'de-*':'de_DE',
            'ja-*':'ja_JP',
            'it-*':'it_IT',
             '*':'en_US'    
        }; 

var lookup = browLoc.split("-")[0] + "-*";
var code = Routes[lookup] || Routes["*"];
console.log(code);