title: Javascript Array key as variable
body: <p>I im building and array where my array key is from a variable like this:</p>
  
  <pre><code>var product_id = $('#product_id').val(); //22
  var art = $('#article_id').val(); //229
  var stk =  $('#stk').val(); //20
  var elements = [];
  elements [art] = stk;
  console.log(elements);
  </code></pre>
  
  <p>This is the result</p>
  
  <pre><code>Array[229]
  228:"20"
  length:229
  __proto__:Array[0]
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/uVQGn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uVQGn.png" alt="console.log"></a></p>
  
  <p>As you see the result, it actually created 229 array key,</p>
  
  <p>When I make a AJAX POST with that variable. It post all 229 array item to it.</p>
  
  <pre><code>option[]:
  option[]:
  option[]:
  option[]:
  option[]:
  option[]:
  option[]:
  option[]:
  option[]:
  option[]:
  option[]:
  option[]:20
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ymwTH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ymwTH.png" alt="post object"></a></p>
  
  <p>It is possible I just want to post 1 key and value.</p>
  
  <pre><code>elements[229] = 20;
  </code></pre>
  
  <p>Not all the unused. Thanks!</p>
  
  <p>Below is my ajax call</p>
  
  <pre><code>$.ajax({
              url: 'product/getprice',
              type: 'post',
              data: { product_id: product_id, option: element },
              dataType: 'text',
              beforeSend: function() {
              },
              complete: function() {
  
              },
              success: function(json) {
  
                  json = JSON.parse(json);
  
               },
              error: function(xhr, ajaxOptions, thrownError) {
                  alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
              }
          });
  </code></pre>