Please explain what is happening in this loop

I haven’t made sense of why oldLetterArray[j].length is only printed 4 times. before the loop starts over. There are 7 items in the array. The first array has 10, 2nd has 2, then 4,5, 1,2, and 2 respectively.

@aimster - see instruction Tips a-d plus example - first think about using a for … in loop to iterate over the keys (pointValue) within the old object (oldPointStructure ); then imbed for loop to index count thru the length ((oldPointStructure[pointValue].length) of each key of old objects. Note: Seemed that I had to remember that keys are string type; and we want to use them as values so I had to convert to number.

@Aimster Take a close look at your for statements where you set up each of those two loops. Make sure you’re incrementing the loop variables the way you meant to.

Yeah, I realize it wasn’t going to give me what I wanted. But I still didn’t understand the output it was giving based on the loop variables I had…

Hmm that is interesting, you don’t by chance still have this version of the whole file do you? The output would depend on the form of oldPointStructure

That bad boy is gone now, lol. oldPointStructure was the object given to us though.

@Aimster - in CH 14 Global Scope - it talks about making sure you declare/init let i = 0 (v. i=0) in for loop iterations - if not it could disrupt how well loop operates and if left off treats variable as global - maybe this was why?

1 Like