How do I loop through or enumerate a JavaScript object?

You have to use the for-in loop

for (var prop in p) {
    if (!p.hasOwnProperty(prop)) {
        //The current property is not a direct property of p
        continue;
    }
    //Do your logic with the property here
}

Published: January 10 2018

blog comments powered by Disqus