Q:

Saving a json file in Javascript by overwrighting the previous one

I am a beginner in JS and trying to generate a json format file and saving it through this code
<script>
    var jsonArr=[];
//Generating 5 random test data for json array
for(var i = 0; i < 5; i++) {
    jsonArr.push({
        team: "teamA",
        matchname: "Match1",
        score: "32"
    });  } 
json_str = JSON.stringify(jsonArr); //stringify json

//Save file function
saveFile('yourfilename.json', "data:application/json", new Blob([json_str],{type:""}));

function saveFile (name, type, data) {
    if (data != null && navigator.msSaveBlob)
        return navigator.msSaveBlob(new Blob([data], { type: type }), name);

    var a = $("<a style='display: none;'/>");
    var url = window.URL.createObjectURL(new Blob([data], {type: type}));
    a.attr("href", url);
    a.attr("download", name);
    $("body").append(a);
    a[0].click();
    setTimeout(function(){  // fixes firefox html removal bug
        window.URL.revokeObjectURL(url);
        a.remove();
    }, 500);  
}

</script>

This code is working but i want to save this file to a specific directory with overwriting the previous saved file.If anybody can help?
Thanks

A:

It isn't possible with Javascript to access the file system of the client. You can only prompt the user with a download dialog or force a download to the default download directory.

