So, I grab JSON through AJAX, but I need to re-configure it. Part of this means using the string contained in the variable as the name of the property of the nested object.
But Javascript does not allow this. It treats variables as literal strings, instead of reading the value.
Here is a snippet:
var pvm.exerciseList = []; $.get('folder_get.php', function(data){ var theList = $.parseJSON(data); $.each(theList, function(parentFolder, files) { var fileList = []; $.each(files, function(url, name) { thisGuy.push({fileURL: url, fileName: name}); }); pvm.exerciseList.push({parentFolder: fileList}); }); });
Anyway, around? I need to extract the string contained in "parentFolder". Now JS just interprets it literally.
source share