JSON from $.each()

Posted by Matthew on Stack Overflow See other posts from Stack Overflow or by Matthew
Published on 2010-03-27T21:31:20Z Indexed on 2010/03/27 21:33 UTC
Read the original article Hit count: 193

Filed under:
|

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());
 });

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JSON