Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>var numeric = [ ['input1','input2'], ['input3','input4'] ]; numeric[0][0] == 'input1'; numeric[0][1] == 'input2'; numeric[1][0] == 'input3'; numeric[1][1] == 'input4'; var obj = { 'row1' : { 'key1' : 'input1', 'key2' : 'input2' }, 'row2' : { 'key3' : 'input3', 'key4' : 'input4' } }; obj.row1.key1 == 'input1'; obj.row1.key2 == 'input2'; obj.row2.key1 == 'input3'; obj.row2.key2 == 'input4'; var mixed = { 'row1' : ['input1', 'inpu2'], 'row2' : ['input3', 'input4'] }; mixed.row1[0] == 'input1'; mixed.row1[1] == 'input2'; mixed.row2[0] == 'input3'; mixed.row2[1] == 'input4'; </code></pre> <p><a href="http://jsfiddle.net/z4Un3/" rel="noreferrer">http://jsfiddle.net/z4Un3/</a></p> <p>And if you're wanting to store DOM elements:</p> <pre><code>var inputs = [ [ document.createElement('input'), document.createElement('input') ], [ document.createElement('input'), document.createElement('input') ] ]; inputs[0][0].id = 'input1'; inputs[0][1].id = 'input2'; inputs[1][0].id = 'input3'; inputs[1][1].id = 'input4'; </code></pre> <p>Not real sure how useful the above is until you attach the elements. The below may be more what you're looking for:</p> <pre><code>&lt;input text="text" id="input5"/&gt; &lt;input text="text" id="input6"/&gt; &lt;input text="text" id="input7"/&gt; &lt;input text="text" id="input8"/&gt; var els = [ [ document.getElementById('input5'), document.getElementById('input6') ], [ document.getElementById('input7'), document.getElementById('input8') ] ]; els[0][0].id = 'input5'; els[0][1].id = 'input6'; els[1][0].id = 'input7'; els[1][1].id = 'input8'; </code></pre> <p><a href="http://jsfiddle.net/z4Un3/3/" rel="noreferrer">http://jsfiddle.net/z4Un3/3/</a></p> <p>Or, maybe this:</p> <pre><code>&lt;input text="text" value="4" id="input5"/&gt; &lt;input text="text" value="4" id="input6"/&gt; &lt;br/&gt; &lt;input text="text" value="2" id="input7"/&gt; &lt;input text="text" value="4" id="input8"/&gt; var els = [ [ document.getElementById('input5'), document.getElementById('input6') ], [ document.getElementById('input7'), document.getElementById('input8') ] ]; var result = []; for (var i = 0; i &lt; els.length; i++) { result[result.length] = els[0][i].value - els[1][i].value; } </code></pre> <p>Which gives:</p> <pre><code>[2, 0] </code></pre> <p>In the console. If you want to output that to text, you can <code>result.join(' ');</code>, which would give you <code>2 0</code>.</p> <p><a href="http://jsfiddle.net/z4Un3/6/" rel="noreferrer">http://jsfiddle.net/z4Un3/6/</a></p> <p><strong>EDIT</strong></p> <p>And a working demonstration:</p> <pre><code>&lt;input text="text" value="4" id="input5"/&gt; &lt;input text="text" value="4" id="input6"/&gt; &lt;br/&gt; &lt;input text="text" value="2" id="input7"/&gt; &lt;input text="text" value="4" id="input8"/&gt; &lt;br/&gt; &lt;input type="button" value="Add" onclick="add()"/&gt; // This would just go in a script block in the head function add() { var els = [ [ document.getElementById('input5'), document.getElementById('input6') ], [ document.getElementById('input7'), document.getElementById('input8') ] ]; var result = []; for (var i = 0; i &lt; els.length; i++) { result[result.length] = parseInt(els[0][i].value) - parseInt(els[1][i].value); } alert(result.join(' ')); } </code></pre> <p><a href="http://jsfiddle.net/z4Un3/8/" rel="noreferrer">http://jsfiddle.net/z4Un3/8/</a></p>
 

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