Javascript Object.propertyIsEnumerable ()

A JavaScript Object.propertyIsEnumerable () metódus ellenőrzi, hogy az adott tulajdonság felszámolható-e és az objektum saját tulajdon-e.

A propertyIsEnumerable()módszer szintaxisa :

 obj.propertyIsEnumerable(prop)

Itt objvan egy tárgy.

propertyIsEnumerable () Paraméterek

A propertyIsEnumerable()módszer:

  • prop - A tesztelni kívánt tulajdonság neve.

Visszatérési érték a propertyIsEnumerable ()

  • Visszaadja, Booleanhogy a megadott tulajdonság megszámlálható-e, és az objektum saját tulajdon-e.

Megjegyzés: Minden objektumnak van egy propertyIsEnumerablemetódusa. Ez a módszer meghatározhatja, hogy az objektumban megadott tulajdonság felszámolható-e egy for… inhurokkal.

Példa: Az Object.propertyIsEnumerable () használata

 let arr = (1, 2, 3, 4); console.log(arr.propertyIsEnumerable(0)); // true console.log(arr.propertyIsEnumerable("length")); // false console.log(Math.propertyIsEnumerable("random")); // false let obj = ( prop: "Hello World!", ); console.log(obj.propertyIsEnumerable("prop")); // true // property does not exist console.log(obj.propertyIsEnumerable("random")); // false

Kimenet

 igaz hamis hamis igaz

Ajánlott olvasmány: Javascript Object getPrototypeOf ()

érdekes cikkek...