create string from all checked values jQuery

javascript, jquery

Solution

Functional programming:

var str = $('.checkBoxClass:checked').map(function() {
    return this.value;
}).get().join();

Reference: `.map`, `.get`, `.join`

Problem

Ok so I do this: ``` <input type="checkbox" class="checkBoxClass" value="0" /> <input type="checkbox" class="checkBoxClass" value="1" /> <input type="checkbox" class="checkBoxClass" value="2" /> ``` Then in javascript/jquery I'm trying to do something like this: ``` $('#btnHtml').click(function(){ for( var checks=''; $('.checkBoxClass:checked').val() ){ var checks = checks+', '; } }); ``` Let's say all of those checkboxes are checked, how can I get `var checks` to be a string of `'0, 1, 2'` ? Still trying to get used to the for() in JS, it might be the completely wrong way of going about it. Not sure how to do this.

Original source