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 obj
van 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,
Boolean
hogy a megadott tulajdonság megszámlálható-e, és az objektum saját tulajdon-e.
Megjegyzés: Minden objektumnak van egy propertyIsEnumerable
metódusa. Ez a módszer meghatározhatja, hogy az objektumban megadott tulajdonság felszámolható-e egy for… in
hurokkal.
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 ()