I'm trying to get a valid json from the data but JSON.stringify()
returns only some values.
js file
var images = [];
[...files].forEach(function (file) {
var reader = new FileReader();
var srcData = file.webkitRelativePath;
reader.onloadend = function () {
images.push(reader.result);
};
reader.readAsDataURL(file);
images.push(srcData);
});
This results in the following output:
Though after var temp = JSON.stringify({ images });
I only get the first 2 values even though all the values are strings.
> console.log(temp)
// prints
{"images":["images/1.jpg","images/1.png"]}
Any reason why JSON.stringify()
acts like that?