Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate an HTML Dropdown From a Javascript Array Without Duplicates
    primarykey
    data
    text
    <p>Using a <a href="https://stackoverflow.com/questions/11255219/use-a-javascript-array-to-fill-up-a-drop-down-select-box">previously answered SO question</a> as a reference, I created a function that populates a dropdown list in my HTML doc from an existing javascript array.</p> <p>Here's the HTML:</p> <pre><code>&lt;fieldset&gt; &lt;legend&gt;Choose action&lt;/legend&gt; &lt;p&gt;Choose your action and click next&lt;/p&gt;&lt;br /&gt; &lt;select id="trigger"&gt;&lt;/select&gt; &lt;/fieldset&gt; </code></pre> <p>Here's the Javascript:</p> <pre><code>var guns = [ ["Smith and Wesson 500", "Revolver", "Full Frame", 50, "sada"], //model, type, frame, cal, trigger ["Glock 19", "Semi", "Compact", 9, "striker"], ["Smith and Wesson M and P Shield 9", "Semi", "Compact", 9, "striker"], ["Ruger Alaskan", "Revolver", "Full Frame", 44, "dao"], ["Ruger SR9", "Semi", "Compact", 9, "striker"], ["Desert Eagle", "Semi", "Full Frame", 50, "sada"], ["Smith and Wesson M and P Shield 40", "Semi", "Compact", 40, "striker"] ] var triggerDropdown = function(){ var sel = document.getElementById('trigger'); for (var i = 0; i &lt; guns.length; i++) { var opt = document.createElement('option'); opt.innerHTML = guns[i][4]; opt.value = guns[i][4]; sel.appendChild(opt); } }; </code></pre> <p><strong>My challenge:</strong></p> <p>Populate <code>trigger</code> <em>without duplicates</em>. Also, the solution must not require me to permanently change <code>guns</code> (I found a few other helpful SO posts, but most of them involve first removing duplicates from the array...in this case, I don't have the option).</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload