0

Time for some more education.

I've come across a javascript 'for loop' which loops through a nested object. What does the ,10 portion, represent in the condition statement?

 for (var x = 0; x < parseInt(myObj[myCategory][MySubCategory]['amount'], 10); x++)
 {
// stuff happens
}

I am not finding any documentation that talks about this so I presume I'm just unclear on what I would even search on. Thanks.

DysonGuy
  • 163
  • 1
  • 11
  • 2
    This would've been much cleaner (and possibly more efficient) if they had put `var length = parseInt(myObj[myCategory][MySubCategory]['amount'], 10);` in front of the loop, then have a `x < length` condition. – Bergi Sep 21 '19 at 20:27

1 Answers1

1

Notice, in your example, that 10 is the 2nd argument of the parseInt function.

The ,10 is for specifying a base of 10.

See radix.

You'd think base 10 would be the default, but it isn't; you need to specify this each time you call the parseInt function.

Lonnie Best
  • 9,936
  • 10
  • 57
  • 97