473,387 Members | 1,621 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,387 software developers and data experts.

referencing an object's fieldnames

Hi,

A have an array of objects defined like this:

var collegas =
[{smtp:'a***************@king.dom',voornaam:'Alberi c',famnaam:'Verhelst'},
{smtp:'a************@king.dom',voornaam:'Anita',fa mnaam:'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[i]) {
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

Apr 12 '06 #1
2 1140
Ward <ki**********@forpresident.com> wrote in
news:Xn**********************************@195.130. 132.70:
Hi,

A have an array of objects defined like this:

var collegas =
[{smtp:'a***************@king.dom',voornaam:'Alberi c',famnaam:'Verhelst
'},
{smtp:'a************@king.dom',voornaam:'Anita',fa mnaam:'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[i]) {
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
Apr 12 '06 #2
Ward said on 13/04/2006 8:10 AM AEST:
Ward <ki**********@forpresident.com> wrote in
news:Xn**********************************@195.130. 132.70:

Hi,

A have an array of objects defined like this:

var collegas =
[{smtp:'a***************@king.dom',voornaam:'Alberi c',famnaam:'Verhelst
'},
{smtp:'a************@king.dom',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[i]) {
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[i] ){
// collegas[i] has an element [i]
// with a property called 'smtp'
}
Depending on what the value of the property is set to, it might be OK to
use:

if ( collegas[i].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.
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>
Apr 13 '06 #3

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

Similar topics

3
by: Josep | last post by:
Hi, I'd like to poll a database and get the table contents, as well as the field names from that table. I've been to php.net but this time I cannot find something helpful. I can get the data,...
7
by: | last post by:
How do I get to the fieldnames of a table in a recordset? I have a recordset which I output into HTML. And on data from certian columns I need to perform different actions. I would like to...
4
by: Little PussyCat | last post by:
Hello, I have had a request, one of our tables is used as a report and I have been asked that all fieldnames for months have dashes in them, like Jan-05 instead of Jan05 and so on... Now what...
16
by: phpcode | last post by:
I have a javascript function as follows: function myfunction(formName,formField) { parseInt(document.formName.formField.value) +=1; } Then I can call the function when needed like this: ...
4
by: mrgr8avill | last post by:
Hello, all. First off, I apologize for my ignorance. I am not used to working with non-variants, and it has been a LONG time since I dealt with OOP. I need to pass a string to a compiled...
1
by: Jay Balapa | last post by:
Hello, Iam creating a query page, in which a Drop Down List will have collection of fieldnames. Is there a elegant way of doing it? Currently Iam opening up a datareader and using...
3
by: Beren | last post by:
Hello, I have an sproc to query a couple of tables, that have the same fieldnames, for example DateCreated. ------------------------------------- Select a.* , b.* From tablea a Join table b...
6
by: Miles Keaton | last post by:
Is there a simple way to list fieldnames in a table, from PHP? When on the command-line, I just do \d tablename But how to get the fieldnames from PHP commands? ...
6
by: Gerrit | last post by:
Hello, I try to display the fieldnames and the primary key of a table, with this code: using System; using System.Collections.Generic; using System.Text; using System.Data; using...
2
by: john | last post by:
In the query builder I made an edit-query in which I have linked table A to table B on IDnr. For every record that matches I want 5 fields of table A to get the values of corresponding fields in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.