After receiving a JSON response from the server and converting it into a Javascript object, the structure looks like this:
var response = {
key1:[],
key2:[],
key3:[],
key4:[],
key5:[]
}
Once the request is complete, the response
object appears as follows:
Object (*expandable):
key1: Array[0]
key2: Array[0]
key3: Array[0]
key4: Array[20]
key5: Array[113]
Next, I aim to store this information in a database. To validate the response object, I use console.log
within a defined function (and that's where things get interesting - explained in the comments):
function setupDatabase(){
console.log(response); // accurately displays the response
console.log(response.key5); // shows key5: Array[0]. Upon expanding, all elements are visible.
console.log("key5: "+response.key5.length);// logs 0!!
}
It's expected for the initial 3 keys to display 0, considering they have no returned elements. The last 2 keys, however, seem fine. Yet, why does the third console.log
command yield 0 despite checking the same object? Am I overlooking anything?