जावास्क्रिप्ट Object.getOwnPropertyNames () विधि किसी दिए गए ऑब्जेक्ट में पाए गए सभी गुणों की एक सरणी देता है।
getOwnPropertyNames()
विधि का सिंटैक्स है:
Object.getOwnPropertyNames(obj)
getOwnPropertyNames()
विधि, एक स्थिर विधि जा रहा है, का उपयोग करते हुए कहा जाता है Object
वर्ग के नाम।
getOwnPropertyNames () पैरामीटर
getOwnPropertyNames()
विधि में लेता है:
- obj - वह वस्तु जिसके गुण और गैर-गुणांक गुण लौटाने हैं।
GetOwnPropertyNames () से वापसी मान
- दिए गए ऑब्जेक्ट में सीधे पाए जाने वाले गुणों के अनुरूप स्ट्रिंग्स की एक सरणी देता है।
ध्यान दें: सभी enumerable अपने गुणों Object.getOwnPropertyNames()
को Object.keys()
वापस करते हुए ऑब्जेक्ट के सभी गुण लौटाता है।
उदाहरण: getOwnPropertyNames () का उपयोग करना
// array object let arr = ("a", "b", "c"); console.log(Object.getOwnPropertyNames(arr)); // ( '0', '1', '2', 'length' ) // array-like objects let obj = ( 65: "A", 66: "B", 67: "C" ); console.log(Object.getOwnPropertyNames(obj)); // ( '65', '66', '67' ) // non-enumerable properties are also returned let obj1 = Object.create( (), ( getValue: ( value: function () ( return this.value; ), enumerable: false, ), ) ); obj1.value = 45; console.log(Object.getOwnPropertyNames(obj1)); // ( 'getValue', 'value' )
आउटपुट
('0', '1', '2', 'लंबाई') ('65', '66', '67') ('getValue', 'value')
अनुशंसित पढ़ना: जावास्क्रिप्ट ऑब्जेक्ट ।hasOwnProperty ()