How to iterate over a JavaScript object?

For most objects, use for .. in : With ES6, if you need both keys and values simultaneously, do To avoid logging inherited properties, check with hasOwnProperty : You don’t need to check hasOwnProperty when iterating on keys if you’re using a simple object (for example one you made yourself with {}). This MDN documentation explains more generally how to deal with objects … Read more

What is the difference between range and xrange functions in Python 2.X?

In Python 2.x: range creates a list, so if you do range(1, 10000000) it creates a list in memory with 9999999 elements. xrange is a sequence object that evaluates lazily. In Python 3: range does the equivalent of Python 2’s xrange. To get the list, you have to explicitly use list(range(…)). xrange no longer exists.