A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-object-getownpropertynames-method/ below:

JavaScript Object getOwnPropertyNames() Method - GeeksforGeeks

JavaScript Object getOwnPropertyNames() Method

Last Updated : 12 Jul, 2025

The Object.getOwnPropertyNames() method in JavaScript is a standard built-in object which returns all properties that are present in a given object except for those symbol-based non-enumerable properties.

Syntax:
Object.getOwnPropertyNames(obj)
Parameters:

This method accepts a single parameter as mentioned above and described below: 

Return value:

Example 1: In this example, we will check if an object contains some properties or not using the Object.getOwnPropertyNames() method in JavaScript.

javascript
const gfg = {
    val1: "Geek1",
    val2: "Geek2",
    val3: "Geek3",
    val4: "Geek4"
};
console.log(Object.getOwnPropertyNames(gfg));

let gfg2 = { val1: 'Geek1', val2: 'Geek2', val3: 'Geek3' };
console.log(Object.getOwnPropertyNames(gfg2).sort());

Object.getOwnPropertyNames(gfg2).
    forEach(function (val, idx, array) {
        console.log(val + ': ' + gfg2[val]);

    }); 

Output: 

Array ["val1", "val2", "val3", "val4"]
Array ["val1", "val2", "val3"]
"val1 : Geek1"
"val2 : Geek2"
"val3 : Geek3"

Example 2: In this example, we will check if an object contains some properties or not using the Object.getOwnPropertyNames() method in JavaScript.

javascript
function ParentClass() { }
ParentClass.prototype.inheritedMethod = function () { };

function ChildClass() {
    this.prop = 5;
    this.method = function () { };
}
ChildClass.prototype = new ParentClass;
ChildClass.prototype.prototypeMethod = function () { };

console.log(
    Object.getOwnPropertyNames(
        new ChildClass()
    )
);

let my_obj = Object.create({}, {
    getFoo: {
        value: function () { return this.foo; },
        enumerable: false
    }
});
my_obj.foo = 1;

console.log(Object.getOwnPropertyNames(my_obj).sort());

Output: 

Array ["prop", "method"]
Array ["foo", "getFoo"]

We have a complete list of Javascript Object methods, to check those please go through this JavaScript Object Complete Reference article.

Supported Browsers:

The browsers supported by Object.getOwnPropertyNames() method are listed below:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4