title: How to get the index of one specific element within an javascript object
body: <p>I have been working on this problem for the second day now and I simply can't seem to find the right way to do it.</p>
  <p><strong>Problem</strong>:
  I need to send the index value of a chosen element within a javascript object to an action in PHP. So when the user chooses a certain element, the index value of said element within the object should be send to the mentioned PHP action.</p>
  <p>What I have so far is the following:</p>
  <p>The button for the jump:</p>
  <pre><code>&lt;!-- Button to jumpo tp specific dashboard. The select and and option tags will be generated dynamicly --&gt;
  &lt;div style=&quot;float:right; margin-right: 10px;&quot;&gt;
  &lt;select name=&quot;idDashboards&quot; id=&quot;idDashboards&quot;&gt;
    &lt;option value=&quot;&quot;&gt;Jump to Dashboard&lt;/option&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  </code></pre>
  <p>The Array itself as well as how the HTML elements are created</p>
  <pre><code>// The array with the dashboards as I get it from the server
  var dashboardArray = &lt;?php echo json_encode(CHtml::listData($dashboards, 'iddashboard', 'title')); ?&gt;;
  
  // Loop through the elements in the dashboardArray and then create option elements to be added to the above create select element.
    for (var idDashboard in dashboardArray) {
      $('#idDashboards').append($(document.createElement('option')).prop({
        value: idDashboard,
        text: dashboardArray[idDashboard].charAt(0).toUpperCase() + dashboardArray[idDashboard].slice(1)
      }));
    };
  </code></pre>
  <p>How the object looks like when I log it.</p>
  <pre><code>{2: &quot;Dashboard_Test_1&quot;, 3: &quot;Dashboard_Test_2&quot;, 4: &quot;Dashboard_Test_3&quot;, 6: &quot;Dashboard_Test_4&quot;}
  </code></pre>
  <p>What I have been trying so far:</p>
  <pre><code>var dashboardIndex = -1;
  var i;
  
  // Loop to get the indexes.
   for (i in dashboardArray) {
     if (dashboardArray.hasOwnProperty(i)) {
       dashboardIndex++
       console.log(dashboardIndex+&quot; These are the indexes&quot;);
     }
   }
  
  // Ajax request that sends data to the PHP action
  $(&quot;#idDashboards&quot;).change(function() {
      var idDashboard = $(this).val();
      console.log(&quot;The change happened!&quot;);
      $.ajax({
        url: 'Path/To/PHP/File/And/Action=' + dashboardIndex,
        method: 'GET',
        success: function(result) {
          location.reload();
          console.log(&quot;So far, so good!&quot;);
        }
      });
    });
  });
  
  </code></pre>
  <p>Now, the dashboardIndex and the index of the elements in the object align and are good. But how do I send the index value of only the element that has been chosen by the user?</p>
  <p>I am very sorry if this is a duplicate but I could not find anything helpful so far. Every advice/help is appreciated.</p>