Array help

So far this is what I have:

var result = JSON.parse(JSON.stringify(result.feed.entry));
                        for(var i = 0; i < result.length; i++){
                        var results = new Array();
                        var obj = {}; 
			            var tube = result[i];
                         obj["tLink"] = tube.link[0].$.href;
						 obj["title"] = tube.title[0];
						 obj["id"] = tube['yt:videoId'][0];
						 obj["pic"] = tube['media:group'][0]['media:thumbnail'][0].$.url;
					results.push(obj);

My results are coming back but as single objects [see 1st attached picture single.png]

What I’m trying to get is [see 2nd attached picture array.png] and I’ve read and read and tried everything I could think of for the last 2 days…soooooo… any help would be greatly appreciated!!!

Happy New Year to you all!!


array.png

for(var i = 0; i < result.length; i++){ var results = new Array();

You are declaring the results array inside the loop. If you want to add things to it, you might want that to be on the outside of the loop rather than creating a new one on each iteration.

Thank you for the input :slight_smile: I did figure it out like this …

 var entries = JSON.parse(JSON.stringify(result.feed.entry)),
                            results = [];
                        for (var i = 0, entry; entry = entries[i]; i++) results.push({
                            'tLink': entry.link[0].$.href,
                            'title': entry.title[0],
                            'id': entry['yt:videoId'][0],
                            'pic': entry['media:group'][0]['media:thumbnail'][0].$.url
                        });
Sponsor our Newsletter | Privacy Policy | Terms of Service