Get a list of all the properties of an object?

Can someone please tell me how to get a list of all the properties of an object including the ones which are not “OwnPRoperties” i.e. which an object inherits by default. ??

For example the below list, they were not defined in an object but still they exist :

defineGetter
defineSetter
lookupGetter
lookupSetter
proto
city
constructor
greet
hasOwnProperty
isPrototypeOf
propertyIsEnumerable
toLocaleString
toString
toValueOf

This was a more technical question than I thought! I would look at the data file for something like this. Here is a link for the possible solution.
http://www.csharp-examples.net/reflection-property-names/
Code: using System.Reflection; // reflection namespace

// get all public static properties of MyClass type
PropertyInfo propertyInfos;
propertyInfos = typeof(MyClass).GetProperties(BindingFlags.Public |
BindingFlags.Static);
// sort properties by name
Array.Sort(propertyInfos,
delegate(PropertyInfo propertyInfo1, PropertyInfo propertyInfo2)
{ return propertyInfo1.Name.CompareTo(propertyInfo2.Name); });

// write property names
foreach (PropertyInfo propertyInfo in propertyInfos)
{
Console.WriteLine(propertyInfo.Name);
}

1 Like

@robheyays Not sure what this has to do with C#?

@naruto199351 You can give this MDN article a look

1 Like

Thanks for the link @lasjorg . I think it might solve the issue, I’ll give it a look.

Somewhere In an article , I saw that to show all the properties of an object we can write Object_name followed by a period for example hound. But it is not working for me .

This is the link , in the section “Prototype chain”. Please let me know if it works for you .

Dotting onto the object should give you an auto-complete list. But in an editor it will not show you all the properties (that would be annoying and useless).

If you create and log the object in the browser console you can twirl open each property and dotting on to the object will show you the other properties as well.

2 Likes

Your right! It was only for a reference and because I couldn’t find a JavaScript answer.