Let's analyze the code snippet below:
var array = [];
var obj = [{id: "xxxxx", name: "Friend name"}, {id: "xxxxx", name: "Friend name"}]
for (x in obj){
array.push(x.name)
}
After running this code, the array ends up with the correct length but is filled with null values. I found that changing 'obj.name' to a random string resolved the issue. It's important to note that this problem arose while using angular.js and iterating over parsed JSON data. However, even when I tried with a simple array of dictionaries named "obj," the problem persisted.
I suspect that the issue lies in pushing a dictionary value into an array. Can someone confirm if my assumption is correct? If so, what am I doing wrong?
Thank you in advance!