How to loop through or enumerate a JavaScript object?

Posted by Editorial Staff | Updated on

If you want to loop through or enumerate a JavaScript object? You can use the for-in loop as shown by others. However, you also have to make sure that the key you get is an actual property of an object, and doesn’t come from the prototype.

Here is the snippet:

For-of with Object.keys() alternative:


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers