1

I am trying to use an array to get a specific result but i get the error cannot read property of undefined but when i console log that same property i get my result here is my code :

for (var j=0;j<$scope.ftListe.length;j++){
    if(task[j].projet_id==id){
        if(temp!=task[j].NomTache)
            temptache.push(task[j]);
        tempcol.push(lecollaborateur[j]);
    }
    temp=task[j].NomTache;
}
$scope.temptache=temptache;
$scope.tempcol=tempcol;

for(var i=0; i<temptache.length;i++){
    for (var k=0;k<$scope.ftListe.length;i++){
        console.log("l'id de la tache: "+temptache[i].IdTache);
        if(temptache[i].IdTache==$scope.ftListe[k].tacheid){
            temps = temps+$scope.ftListe[k].TempsPasse;
            passe= passe+$scope.ftListe[k].TempsPasse * lecollaborateur[k].CoutParJour;
        }
    }
    tempsAr.push(temps);
    passeAr.push(passe);
    temps=0; passe=0;
}

The property I get the error from is IdTache, what am I doing wrong?

3
  • console temptache and check if it has IdTache? Commented May 29, 2017 at 14:08
  • @Dinesh when i console temptache[i].IdTache I get the result with no problems Commented May 29, 2017 at 14:10
  • If you really want the help, you should provide us with a Plunkr or JSFiddle so we could debug since we can't help like this. Commented May 29, 2017 at 14:20

1 Answer 1

2

Please take a look at the following lines:

for(var i=0; i<temptache.length;i++){
    for (var k=0;k<$scope.ftListe.length;i++){

Note that in the inner for loop, you increment the i variable (i++) instead of k. So this make i to get increment in the inner loop to an out of bounds offset.

The JS runtime error prevent your script from going into an Infinite loop - So when you stated that "when i console log that same property i get my result" it actually show the results up until the point where you're in the valid range of the temptache array.

You should fix it to:

for(var i=0; i<temptache.length;i++){
    for (var k=0;k<$scope.ftListe.length;k++){
Sign up to request clarification or add additional context in comments.

2 Comments

Mondays can be rough ... ;-)
@AlonEitan , i completely missed that, thank you all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.