Creating a non-enumerable property with Object.defineProperty

We've seen in previous recipes how to avoid having properties overridden. There are situations where we might not want a property to be read. Recall the Object.entries method, which creates an iterator of all the properties and values on the object. Well, that's not precisely true. It creates an iterator of all the enumerable properties.

In this recipe, we'll see how to create properties that won't be included in the iterator.

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.