VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-object-getownpropertynames-method/

⇱ JavaScript Object getOwnPropertyNames() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

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: 

  • obj: This parameter holds the object whose enumerable and non-enumerable properties are to be returned.

Return value:

  • This method returns an array of strings that corresponds to the properties found directly in the given object.

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

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.

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:

  • Google Chrome
  • Edge
  • Firefox
  • Opera
  • Safari
Comment