Create checkbox list from related divs <p>I need to create number of checkbox based on the number of array values returned from jQuery. Here is my code:</p> <pre><code>&lt;div class="bob" data-xyz="fish"&gt;&lt;/div&gt; &lt;div class="bob" data-xyz="dog"&gt;&lt;/div&gt; &lt;div class="bob" data-xyz="fish"&gt;&lt;/div&gt; &lt;div class="bob" data-xyz="cat"&gt;&lt;/div&gt; &lt;div class="bob" data-xyz="fish"&gt;&lt;/div&gt; </code></pre> <p>Ineed to display the result value in HTML like this:</p> <pre><code>&lt;label&gt; &lt;input class="fish" type="checkbox" /&gt; fish &lt;/label&gt; &lt;label&gt; &lt;input class="cat" type="checkbox" /&gt; cat &lt;/label&gt; &lt;label&gt; &lt;input class="dog" type="checkbox" /&gt; dog &lt;/label&gt; </code></pre> <p>This is what I tried:</p> <pre><code>var items = {}; $('div.bob').each(function() { items[$(this).attr('data-xyz')] = true; }); var result = new Array(); for(var i in items) { result.push(i); } alert(result); </code></pre>