5 ways to iterate over objects in JS

1.for in

The for in loop is the most basic way to traverse an object, and it also gets the properties on the object’s prototype chain

// Create an object and specify its prototype, bar is a property on the prototype

 const obj = Object . create ( { bar : 'bar' } )

// foo is a property of the object itself

 obj . foo = 'foo' for ( let key in obj ) { console

The post JS 5 ways to iterate over objects first appeared on Lenix Blog .

This article is reprinted from https://blog.p2hp.com/archives/9663
This site is for inclusion only, and the copyright belongs to the original author.