Cannot set property of undefined angularjs : <p>I have a json object s.BdayDetails and i want to change the values of my s.BdayDetails.ProvID into another value.</p>

<p><pre><code></p>

<pre><code> for(var i=0;i&lt;s.BdayDetails.length;i++){
</code></pre>

<p>h.post("../Event/getProvinceName?ProvID=" + s.BdayDetails[i].ProvID).then(function (r) {</p>

                s.BdayDetails[i].ProvID = r.data.toString();


            })
</code></pre>

<p>Returns an error Cannot set property 'ProvID' of undefined. But when I console.log(r.data.toString()) it shows the values.</p>
