I'm trying to append the object from the array. I try to loop through the array but it only appends one element of the array to the object. fiddle: https://jsfiddle.net/maherafrasiab/9ehkfvoc/3/
Edited:
var shers = {};
// the .pbgmain will return the following array.
var all = [{sher: "some text"},{sher: "some text"},{sher: "some text"}];
//basically i want to convert the above array into object.
var data = $('.pbgmain').each(function(i) {
datas = $(this).text().trim();
all.push({sher: datas})
for(var i = 0; i < 10; i++) {
shers = all[i];
}
});
shers. What did you intendshersto be? What would be its properties?10times? What if there's less than 10 items?object. Anobjectonly contains keyed properties (i.e. named properties). I think you're misunderstanding how JavaScript'sobjectandarraytypes work.