102
rated 0 times
[
106]
[
4]
/ answers: 1 / hits: 42739
/ 12 Years ago, sat, june 30, 2012, 12:00:00
I'm trying to loop through a number of items, and create a json object. Each loop should be a new item on the object, but I'm having some issues doing it. It seems that only one set of items gets added, instead of multiple ones.
Here is my code:
jsonObj = {}
rows.each(function (index) {
jsonObj[id] = $this.find('.elementOne').val();
jsonObj[name] = $this.find('.elementTwo').text();
});
Here is what my json looks like:
{
id: 3
name: Stuff
},
Here is what I am trying to do:
{
id: 1
name: Stuff
},
{
id: 2
name: Stuff
},
{
id: 3
name: Stuff
}
More From » jquery