473,394 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to get an Object's properties' name?

Max
Hi, there,

Is there a good way to get an Object's properties' names.
eg. obj={a:"aa",b:"bB",c:"Cc"};
All I mean is to get the names of "a", "b", "c". but not the values
"aa", "bB", "Cc".

Many thanx.
Nov 20 '07 #1
3 1629
VK
On Nov 20, 8:47 pm, Max <Maximus.Zh...@gmail.comwrote:
Hi, there,

Is there a good way to get an Object's properties' names.
eg. obj={a:"aa",b:"bB",c:"Cc"};
All I mean is to get the names of "a", "b", "c". but not the values
"aa", "bB", "Cc".
var obj={a:"aa",b:"bB",c:"Cc"};

for (var prop in obj) {
alert(prop);
}
Nov 20 '07 #2
Max
On 11月21日, 上午2时15分, VK <schools_r...@yahoo.comwrote:
On Nov 20, 8:47 pm, Max <Maximus.Zh...@gmail.comwrote:
Hi, there,
Is there a good way to get an Object's properties' names.
eg. obj={a:"aa",b:"bB",c:"Cc"};
All I mean is to get the names of "a", "b", "c". but not the values
"aa", "bB", "Cc".

var obj={a:"aa",b:"bB",c:"Cc"};

for (var prop in obj) {
alert(prop);

}
Thanks VK,

It is the way.
I just make a function with an object as the argument./* function ({})
{}*/ And the object has some properties that have default values.
and when the parameter do not have all the properties that defined the
default argument object, the missing properties would take the default
values.

thans again.
Nov 21 '07 #3
Max wrote:
On 11鏈21鏃, 涓婂崍2鏃15鍒, VK <schools_r...@yahoo.comwrote:
>On Nov 20, 8:47 pm, Max <Maximus.Zh...@gmail.comwrote:
>>Is there a good way to get an Object's properties' names.
eg. obj={a:"aa",b:"bB",c:"Cc"};
All I mean is to get the names of "a", "b", "c". but not the values
"aa", "bB", "Cc".
var obj={a:"aa",b:"bB",c:"Cc"};

for (var prop in obj) {
alert(prop);

}

Thanks VK,

It is the way.
I just make a function with an object as the argument./* function ({})
{}*/ And the object has some properties that have default values.
This object should not have any enumerable properties, unless some fool
augmented the Object.prototype object.
and when the parameter do not have all the properties that defined the
default argument object, the missing properties would take the default
values.
The for..in operation will yield all properties of the object, whether
they are inherited or not.

The obvious solution is to use a prototype. That requires a user-defined
constructor:

function MyObject()
{
}

An associated prototype object:

MyObject.prototype = {
constructor: MyObject,
a: "defaultA",
b: "defaultB",
c: "defaultC"
};

And a constructor call:

var o = new MyObject();

If the properties of the constructed object are not set in the first place
or they are subject to a `delete' operation, the object will inherit the
properties from its prototype object through the prototype chain, and so the
default values.
PointedEars
Nov 23 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: Thanos Tsouanas | last post by:
Hello. I would like to have a quick way to create dicts from object, so that a call to foo would return obj.bar. The following works, but I would prefer to use a built-in way if one exists. ...
54
by: tshad | last post by:
I have a function: function SalaryDisplay(me) { var salaryMinLabel = document.getElementById("SalaryMin"); salaryMinLabel.value = 200; alert("after setting salaryMinLabel = " +...
8
by: deko | last post by:
I'm hoping someone can sanity check my understanding of the Object Model for Forms/Controls. I'm having trouble drilling down into Control properties. First, I have a record set with the...
7
by: Martin Robins | last post by:
I am currently looking to be able to read information from Active Directory into a data warehouse using a C# solution. I have been able to access the active directory, and I have been able to return...
8
by: a | last post by:
I'm trying to save data from a custom object into the profile object, but it is not structured the way that I want. I'm trying to get the custom object to serialize as xml to a Profile object...
0
by: a | last post by:
I need to create an instance of a custom object 'School.Teacher' and use it in a Profile object. I'm developing a bad case of "Pretzel Logic" thinking about this. Filling the custom object ...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
3
by: Simon Hart | last post by:
Hi, I am trying to implement some functionality as seen in MS CRM 3.0 whereby a basic Xml is deserialized into an object which contains properties. What I want to do from here is; cast the basic...
11
by: manstey | last post by:
Hi, I am having trouble designing my classes. I have two classes. The first one wraps around an old-style class called oref Class CacheClass(object): def __init__(self, obj):
11
by: Andrus | last post by:
I'm implementing entity object which should populate its properties from database when property is first referenced. In RDL reports I use object properties like MyObject.MyProperty MyObject...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.