JSON from $.each()
- by Matthew
I'm trying to get a list of the values of all checked checkboxes that looks like this:
foo = {
'colors': ['blue', 'red', 'green'],
'flavors': ['vanilla', 'chocolate']
};
This is the approach I'm taking so far, but JS is saying that 'colors' doesn't exist when I try to push a new value to it. I'm assuming this is a scope issue but I don't know how to fix it.
var foo = {};
foo.colors = [];
$(".colors:checked").each(function(){
foo.colors.push($(this).val());
});