so I am struggling trying to access a -somewhat- complex Array on Javascript.
On a simple way, I have an array like so:
globalForm['prop1'] = anotherArray[];
globalForm['prop2'] = yetAnotherArray[];
If I try to:
console.log(globalForm);
//-or-
JSON.stringify(globalForm)
I get an empty Array [] or an empty JSON object.
But if I do this:
console.log(globalForm['prop1']);
//-or-
JSON.stringify(globalForm['prop1'])
I actually get its contents.
Am I doing something wrong/stupid at trying to log or stringify the whole array? What I am trying to achieve is to create a complex JSON object from that array.
This is my actual code: For prop1:
var completedWeights = [];
globalForm['CompletedFormPhoto'] = images;
var radio_groups = {}
$(".weightRadio:radio").each(function(){
radio_groups[this.name] = true;
});
for(group in radio_groups){
thisGroup = $(".weightRadio:radio[name="+group+"]:checked");
if_checked = !!thisGroup.length;
completedWeights.push({'IdWeight':thisGroup.attr('name'), 'Value':thisGroup.val()});
}
globalForm['CompletedFormWeight'] = completedWeights;
For prop2 (this actually executes before generating prop1):
var fileInput = document.getElementById('fileInput');
var fileDisplayArea = document.getElementById('fileDisplayArea');
fileInput.addEventListener('change', function(e) {
var idImg = Date.now();
var currentImageObj =[];
var file = fileInput.files[0];
var imageType = /image.*/;
var addedImage = document.createElement('div');
addedImage.className = 'addedImage';
if (file.type.match(imageType)) {
var reader = new FileReader();
reader.onload = function(e) {
var img = new Image();
img.src = reader.result;
img.id = idImg;
addedImage.appendChild(img);
var ind = img.src.indexOf(',/9j/') + 5;
currentImageObj["Photo"] = img.src.substr(ind);
images[idImg] = currentImageObj;
}
reader.readAsDataURL(file);
console.log(images);
} else {
addedImage.innerHTML = "File not supported!";
}
addComment = document.createElement('a');
addComment.className = "btn btn-default btn-block addComment";
addComment.setAttribute("data-toggle", "modal");
addComment.setAttribute("data-target", "#myModal");
addComment.text = "Agregar Comentario";
addComment.id = idImg;
addedImage.appendChild(addComment);
fileDisplayArea.appendChild(addedImage);
});
Some examples of the actual content of the arrays:

Thanks in advance.