because IE8 Not supported for versions up to Map object , This paper provides an effective solution for program apes .

This article rewrites Map object , Common set, get, put, clear, remove, delete, forEach, has, containsKey, isEmpty, size  Etc , Trial and normal statement of use and declaration Map Same object :

var map = new Map();

Just copy the following code into <script type="text/javascript"></script> Medium .

function Map() {
        this.elements = new Array();
        //  obtain Map Number of elements
        this.size = function() {
            return this.elements.length;
        },
        //  judge Map Empty or not
        this.isEmpty = function() {
            return (this.elements.length < 1);
        },
        //  delete Map All elements
        this.clear = function() {
            this.elements = new Array();
        },
        //  towards Map Add elements to (key, value)
        this.put = function(_key, _value) {
            if (this.containsKey(_key) == true) {
                if (this.containsValue(_value)) {
                    if (this.remove(_key) == true) {
                        this.elements.push({
                            key : _key,
                            value : _value
                        });
                    }
                } else {
                    this.elements.push({
                        key : _key,
                        value : _value
                    });
                }
            } else {
                this.elements.push({
                    key : _key,
                    value : _value
                });
            }
        },
        //  towards Map Add elements to (key, value)
        this.set = function(_key, _value) {
            if (this.containsKey(_key) == true) {
                if (this.containsValue(_value)) {
                    if (this.remove(_key) == true) {
                        this.elements.push({
                            key : _key,
                            value : _value
                        });
                    }
                } else {
                    this.elements.push({
                        key : _key,
                        value : _value
                    });
                }
            } else {
                this.elements.push({
                    key : _key,
                    value : _value
                });
            }
        },
        //  Delete assignments key Elements of , Successfully returned true, Failed return false
        this.remove = function(_key) {
            var bln = false;
            try {
                for (i = 0; i < this.elements.length; i++) {
                    if (this.elements[i].key == _key) {
                        this.elements.splice(i, 1);
                        return true;
                    }
                }
            } catch (e) {
                bln = false;
            }
            return bln;
        },

        //  Delete assignments key Elements of , Successfully returned true, Failed return false
        this.delete = function(_key) {
            var bln = false;
            try {
                for (i = 0; i < this.elements.length; i++) {
                    if (this.elements[i].key == _key) {
                        this.elements.splice(i, 1);
                        return true;
                    }
                }
            } catch (e) {
                bln = false;
            }
            return bln;
        },
        
        //  Get specified key Element value of value, Failed return null
        this.get = function(_key) {
            try {
                for (i = 0; i < this.elements.length; i++) {
                    if (this.elements[i].key == _key) {
                        return this.elements[i].value;
                    }
                }
            } catch (e) {
                return null;
            }
        },

        // set appoint key Element value of value
        this.setValue = function(_key, _value) {
            var bln = false;
            try {
                for (i = 0; i < this.elements.length; i++) {
                    if (this.elements[i].key == _key) {
                        this.elements[i].value = _value;
                        return true;
                    }
                }
            } catch (e) {
                bln = false;
            }
            return bln;
        },

        //  Gets the element of the specified index ( use element.key,element.value obtain key and value), Failed return null
        this.element = function(_index) {
            if (_index < 0 || _index >= this.elements.length) {
                return null;
            }
            return this.elements[_index];
        },

        //  judge Map Does it contain the specified key Elements of
        this.containsKey = function(_key) {
            var bln = false;
            try {
                for (i = 0; i < this.elements.length; i++) {
                    if (this.elements[i].key == _key) {
                        bln = true;
                    }
                }
            } catch (e) {
                bln = false;
            }
            return bln;
        },

        //  judge Map Does it contain the specified key Elements of
        this.has = function(_key) {
            var bln = false;
            try {
                for (i = 0; i < this.elements.length; i++) {
                    if (this.elements[i].key == _key) {
                        bln = true;
                    }
                }
            } catch (e) {
                bln = false;
            }
            return bln;
        },
        
        //  judge Map Does it contain the specified value Elements of
        this.containsValue = function(_value) {
            var bln = false;
            try {
                for (i = 0; i < this.elements.length; i++) {
                    if (this.elements[i].value == _value) {
                        bln = true;
                    }
                }
            } catch (e) {
                bln = false;
            }
            return bln;
        },

        //  obtain Map All in key Array of (array)
        this.keys = function() {
            var arr = new Array();
            for (i = 0; i < this.elements.length; i++) {
                arr.push(this.elements[i].key);
            }
            return arr;
        },

        //  obtain Map All in value Array of (array)
        this.values = function() {
            var arr = new Array();
            for (i = 0; i < this.elements.length; i++) {
                arr.push(this.elements[i].value);
            }
            return arr;
        };
        
        /**
        * map Traversal array
        * @param callback [function]  Callback function ;
        * @param context [object]  context ;
        */
        this.forEach = function forEach(callback,context){
            context = context || window;
            
            //IE6-8 Write the logic of callback function execution
            var newAry = new Array();
            for(var i = 0; i < this.elements.length;i++) {
                if(typeof  callback === 'function') {
                    var val = callback.call(context,this.elements[i].value,this.elements[i].key,this.elements);
                    newAry.push(this.elements[i].value);
                }
            }
            return newAry;
        }

    }