Reputation: 37
I have 2 arrays I am trying to push, one called potential Word and one allword. allword is a global, and potential is in the function.I only want to push allword on the first pass of the code, so I have the variable pusher, so it will not run again after one run. Only potentialWord will.
the problem is that allwords never sends any data back, while potential word does Even when pusher is 0.
for (var i = 0; i < info.length; i++) {
potentialWord.push(info[i].word);
while (pusher = 0){
allwords.push(info[i].word);
}
}
pusher +=1;
I would like for info to be pushed to both arrays, then after my function is called again, only potential word is pushed while allwords remains the same.
Thank You!
Upvotes: 0
Views: 102
Reputation: 7080
Typo here
while (pusher = 0)
Should be
while (pusher === 0)
or
while (pusher == 0)
Explanation
You should be doing a comparison, which is using ===
or ==
.
Instead the typo used assignment, which is =
.
while (pusher = 0)
will always returns falsy. Because pusher = 0
expression returns 0
, which will be evaluated to false
in JavaScript.
Therefore, the while loop has never run. So, allwords
is empty.
Upvotes: 2