A RetroSearch Logo

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

Search Query:

Showing content from https://webplatform.github.io/docs/javascript/Object/getOwnPropertyNames below:

getOwnPropertyNames · WebPlatform Docs

getOwnPropertyNames Summary

Returns the names of the own properties of an object. The own properties of an object are those that are defined directly on that object, and are not inherited from the object’s prototype. The properties of an object include both fields (objects) and functions.

Syntax
Object.getOwnPropertyNames( object )
object
Required. The object that contains the own properties.
Return Value

An array that contains the names of the own properties of the object.

Examples

The following example creates an object that has three properties and a method. It then uses the getOwnPropertyNames method to obtain the own properties (including the method) of the object.

function Pasta(grain, width, shape) {
     
     this.grain = grain;
     this.width = width;
     this.shape = shape;
     this.toString = function () {
         return (this.grain + ", " + this.width + ", " + this.shape);
     }
 }

 
 var spaghetti = new Pasta("wheat", 0.2, "circle");

 
 var arr = Object.getOwnPropertyNames(spaghetti);
 document.write (arr);

 
 

The following example displays the names of properties that start with the letter ‘s’ in a spaghetti object constructed with the Pasta constructor.

function Pasta(grain, size, shape) {
     this.grain = grain;
     this.size = size;
     this.shape = shape;
 }

 var spaghetti = new Pasta("wheat", 2, "circle");

 var names = Object.getOwnPropertyNames(spaghetti).filter(CheckKey);
 document.write(names);

 
 function CheckKey(value) {
     var firstChar = value.substr(0, 1);
     if (firstChar.toLowerCase() == 's')
         return true;
     else
          return false;
 }
 
 
Remarks

The getOwnPropertyNames method returns the names of both enumerable and non-enumerable properties and methods. To return only the names of enumerable properties and methods, you can use the Object.keys Function.

Exceptions

If the value supplied for the object argument is not the name of an object, a TypeError exception is thrown.

See also Other articles Attributions

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