Convert Map to JSON object in Javascript

前端 未结 5 924
青春惊慌失措
青春惊慌失措 2020-12-14 08:22

So Ive got the following javascript which contains a key/value pair to map a nested path to a directory.

function createPaths(aliases, propName, path) {
             


        
5条回答
  •  有刺的猬
    2020-12-14 09:29

    I hope this function is self-explanatory enough. This is what I used to do the job.

    /*
     * Turn the map to an Object so it can be converted to JSON
     */
    function mapToObj(inputMap) {
        let obj = {};
    
        inputMap.forEach(function(value, key){
            obj[key] = value
        });
    
        return obj;
    }
    
    
    JSON.stringify(returnedObject)
    

提交回复
热议问题