Ok..so i have a json string (myJson) that looks like this:
{"id": "1", "file": "test.jpg"}
and in my jquery function, I want to put these id and file values of my json string to an item in an array.
so, i have
var myArray = new Array();
var parsedJson = $.parseJSON(myJson);
myArray['item1']['id'] = parsedJson.id;
myArray['item1']['file'] = parsedJson.file;
but even after the execution of these codes, the length of the array myArray remains zero. Could somebody explain me why this is happening?
Perhaps you’re confusing PHP associative arrays with JavaScript arrays. In JavaScript, you have objects instead of associative arrays and they behave differently. You can try one of the following approaches depending on your needs:
Or this: