Map() is not defined in Google Chrome

前端 未结 4 511
暗喜
暗喜 2021-01-13 03:18

I\'ve been searching for an answer but I\'m only getting results regarding the Google maps API. I\'m trying to use a map in JavaScript to map an integer to a string. Everyth

4条回答
  •  爱一瞬间的悲伤
    2021-01-13 03:51

    Why not use a simple array?

    var NameMap;
    var DistanceMap;
    
    function FillMaps(){
        NameMap = new Array();
        DistanceMap = new Array();
    
        NameMap[01]="Araba/Álava";
    
    }
    
    function CheckName(_field){
        var value = document.getElementsByName(_field.name).item(0).value;
        var location = value.charAt(0) + value.charAt(1);
        var result = NameMap[parseInt(location)];
        if(result == undefined){
            result = "Unknown";
        }
        document.getElementById('loc').innerHTML = result;
    }
    

提交回复
热议问题