Hello )how work for in this case ?In the same way I can use if else statement?

for (let property in duck) {
  if(duck.hasOwnProperty(property)) {
    ownProps.push(property);
  }
}

I don’t understand the question, can you rephrase it?

for…in is a loop, it does not work like a if…else statement if that is what you are asking?

Hi, for … in … is an intrator it loops though an entire group of objects or primitives and returns the value of each of them, on the other hand if … else is a conditional statement, which execute a block of code when the defined condition expression is true. Use the links above to learn more about these two statements from the MDN documentation, it’s valuable resource for all web developer.there you can find information about html elements, css attributes and JavaScript concepts. :wink:

Thank you ):slightly_smiling_face:

I mean what does the

for (let property in duck)

in function)

If you find answers useful give them a like so that in future users can find them easily.

Let’s define duck as an object (il works also with arrays and other collections).


For… in assign the value of the properties in duck to the variable property one ofter the other.

1 Like