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.

1
  • 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. Commented Sep 21, 2019 at 20:27

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.