javascript - Populating an array of objects with a loop -
i'm trying loop through number of items, , create array. each loop should new item in array, i'm having issues doing it. seems 1 set of items gets added, instead of multiple ones.
i've tried below code. please me solve it.
function openpopup3(src,type,title){ var mydata = []; rows.each(function(index) { var temp_obj = {}; temp_obj["src"] = $this.find('.elementone').text(), temp_obj["type"] = $this.find('.elementtwo').text(), temp_obj["title"] = $this.find('.elementthree').text() mydata.push(temp_obj); }); $.magnificpopup.open({ key: 'my-popup', items: mydata, type: 'inline', inline: { markup: '<div class=""><div class="mfp-close"></div>'+'<img class="mfp-src">'+'<div class="mfp-title"></div>'+'</div>' }, gallery: { enabled: true } }); }
what want below:
{ src: "/googleimages/123/a.png", type: "stuff", title: "title1" }, { src: "/googleimages/123/b.png", type: "stuff", title: "title2" }, { src: "/googleimages/123/c.png", type: "stuff", title: "title3" }
first rows
variable contain? seems not declared anywhere.
second have syntax errors:
temp_obj["src"] = $(this).find('.elementone').text(); temp_obj["type"] = $(this).find('.elementtwo').text(); temp_obj["title"] = $(this).find('.elementthree').text();