javascript - Does a value exist in an Array not working? -



javascript - Does a value exist in an Array not working? -

so, have function takes 2 arrays of objects, workarr , arr, , match there id property , add together hours property store in workarr array.

var workarr = []; var arr = []; foundid = []; function blah() { var = 0; var j = 0; //add hours for( i=0; < workarr.length ; i++) { for( j=0; j < arr.length ; j++) { //makesure id's match , week within given time frame //also create sure id hasn't visited if( cond1 && !(isinarray(workarr[i].id))) { workarr[j].total = workarr[j].total + arr[j].hrs; foundid.push(workarr[j].id); }//end if id === id }//end j loop }//end loop printarr(foundid); }//end blah() //checks if given id has found //returns true or false function isinarray(id) { homecoming foundid.indexof(id) > -1; }

the problem when print out visited id array, 1 time function ends, there duplicates in it, , there shouldn't because if duplicate found breaks if status , doesn't added found id's. somehow if status isn't weeding out visited id's. please help me solve seemingly easy problem.

javascript arrays

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -