Hello,
This is how you will do this.
function createData() {
var dataToSave = {"result": '"' + toLength.innerText +'"', "count": counter};
var dataArray = new Array();
dataArray[0] = dataToSave;
var savedData = JSON.stringify(dataArray);
writeToFile(filename, savedData);
}
Note: Please note that in a browser this is not going to work, as for security reasons browser is not going to allow javascript to acess the local file system depending upon the zone in which the site is running.
Regards,