Access the an objects keys and the index from an object in a for loop
<p>I want to access the an object keys and the index from an object, <strong>what is the best way to do this?</strong></p>

<p>this is data object:</p>

<pre><code>d={KpiName:"KPI1",  '1/1/2016':"85%",  '1/2/2016':"87%"}
Object {KpiName: "KPI1", 1/1/2016: "85%", 1/2/2016: "87%"}
</code></pre>

<p>this is my for <code>1st</code> loop with output</p>

<pre><code>for (var key in d) { console.log("d[\"key\"]: ", d[key]) }
d["key"]:  KPI1
 d["key"]:  85%
 d["key"]:  87%
</code></pre>

<p>this is what I want to achieve but I thought I could write it better </p>

<p><code>2nd</code> for loop with output</p>

<pre><code>i=1; for (var key in d) { console.log("d[\"key\"]: ", d[key]); console.log("i: ", i); i++}
d["key"]:  KPI1
i:  1
d["key"]:  85%
i:  2
d["key"]:  87%
i:  3
3
</code></pre>

<p>I thought I could write the for loop like this </p>

<pre><code>for (var key, i  in d){...}
</code></pre>

<p>But it does not seem to work, maybe my <code>2nd</code> for loop achieves what I want but I am not sure if it the best code.</p>