0

I'm currently looping around a series of checkboxes that have a specific name assigned to them. Whatever checkbox is checked it gets the value and puts it in an array.

var filterHeight = $('input[name="filter-height"]:checked');
var userArray = [];    

filterHeight.each(function(){
    userArray.push($(this).val());      
});

So the output could be something like short, medium, tall

How would I assign a key value to the array values? I'm looking to do something like:

$(document).trigger('showHeight', {
    short: true,
    medium: false,
    tall: false
    }
});

Any help is appreciated!

1
  • userArray[$(this).val()] = true; Commented Oct 14, 2013 at 23:38

1 Answer 1

2

You need an object so try:

var filterHeight = $('input[name="filter-height"]');
var userObj = {}; 
filterHeight.each(function () {
    userObj[this.value] = this.checked;
});


$(document).trigger('showHeight', userObj);

Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.