enumerable

Meaning: Indicates whether an object attribute can be enumerated.

Let’s take an example of enumerable when we create an object

example
const cat = {}; Object.defineproperty (cat, "price", {value: 100, Enumerable: false, // Default: false}); Object.defineproperty (cat, "name", {value: "jojo", Enumerable: true,}); console.log("price" in cat); // true console.log(cat.hasOwnProperty("price")); // true for (const key in cat) { console.log(key); // name } Object.keys(cat); // nameCopy the code

Directly declared object properties are enumerated by default

const cat = { x: 1, y: 2 };
for (const key in cat) {
  console.log(key); // x , y
}
Object.keys(cat); // x, y
Copy the code

Objects created with object.create () and then copied properties are also enumerable

const cat = { x: 1, y: 2 };
const obj = Object.create(cat);
obj.z = 3;
for (const key in obj) {
  console.log(key); // x, y, z
}
Object.keys(obj); // x, y, z
Copy the code

conclusion

Enumerable: True :true :true: True: True: True: True