OpenSource For You

Destructur­ing in iterators

-

The destructur­ing feature can be used in a for loop when iterating through an array of objects. In the following example, we have an array of books, each with a title and author name. We use a for loop to list only the book titles. In Line 10, we use the destructur­ing feature to only pick the property title. this case, variable c gets the value undefined. thrown in this case. This is called fail-soft.

To avoid a fail-soft situation where the JavaScript engine assigns the value undefined, we can also provide variable c with a default value:

There is no error

Newspapers in English

Newspapers from India