referencing an object's fieldnames

W

Ward

Hi,

A have an array of objects defined like this:

var collegas =
[{smtp:'(e-mail address removed)',voornaam:'Alberic',famnaam:'Verhelst'},
{smtp:'(e-mail address removed)',voornaam:'Anita',famnaam:'Dierens'}, etc


I iterate over this array with this code :

for (var i = 0, stop=collegas.length ; i < stop ; i++) {
for (var veld in collegas) {
etc

I would like to check whether a particular veld instance's name is smtp. In
code what I want is this :
if (veld.fieldName=="smtp") { do something ...

But this syntax doesn't work.

Any help much appreciated.


Ward
 
W

Ward

Hi,

A have an array of objects defined like this:

var collegas =
[{smtp:'(e-mail address removed)',voornaam:'Alberic',famnaam:'Verhelst
'},
{smtp:'(e-mail address removed)',voornaam:'Anita',famnaam:'Dierens'},
etc


I iterate over this array with this code :

for (var i = 0, stop=collegas.length ; i < stop ; i++) {
for (var veld in collegas) {
etc

I would like to check whether a particular veld instance's name is
smtp. In code what I want is this :
if (veld.fieldName=="smtp") { do something ...

But this syntax doesn't work.

Any help much appreciated.


Ward



I was sleeping awake.
if (veld=="smtp") was what i was looking for..

regards,

Ward
 
R

RobG

Ward said on 13/04/2006 8:10 AM AEST:
Hi,

A have an array of objects defined like this:

var collegas =
[{smtp:'(e-mail address removed)',voornaam:'Alberic',famnaam:'Verhelst
'},
{smtp:'(e-mail address removed)',voornaam:'Anita',famnaam:'Dierens'},
etc


I iterate over this array with this code :

for (var i = 0, stop=collegas.length ; i < stop ; i++) {
for (var veld in collegas) {
etc

I would like to check whether a particular veld instance's name is
smtp. In code what I want is this :
if (veld.fieldName=="smtp") { do something ...

But this syntax doesn't work.

Any help much appreciated.


Ward




I was sleeping awake.
if (veld=="smtp") was what i was looking for..


You can also do:

if ( smtp in collegas ){
// collegas has an element
// with a property called 'smtp'
}


Depending on what the value of the property is set to, it might be OK to
use:

if ( collegas.smtp ) {
//...
}

Noting that if the property exists but its value equates to boolean
false (say it's set to the number zero) the test will return false.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,052
Latest member
KetoBeez

Latest Threads

Top