I'm struggling with this. I know this is simple when you know how, but I just can't get the hang of it.
I basically want to create an object like this:
data = [{
a: 1
b: "test"
c: 32
}, {
a: 2
b: "test2"
c: 55
}, {
a: 3
b: "xyz"
c: 103
}]
This is just an example of a larger function, so I don't want to do exactly this, but understanding tis will help me do the larger function.
I would've thought the below would work, but it doesn't quite. I'm guessing it just needs a little tweaking:
var data = new Object;
$('.class-name').each(function () {
var a = $(this).data('a');
var b = $(this).data('b');
var c = $(this).data('c');
data[] = {
a: a,
b: b,
c: c
}
});
I'm struggling with the adding to object thing and also the fact that I'm declaring the object outside the function.
I've tried data.push but I think I'm getting mixed up with arrays and objects.
Thanks for any help.