I've created the following array and want to be able to process each
indivisual object whenever my function is called. Is this best done
with a "foreach"? I don't see a foreach in my javascript book...is
there another way to step threw an array to process each item?
var trvtps = new Array('autoReim b','airRail','c ar','taxi','lod ge','meals','mi sc'); 6 1217 ab*******@hotma il.com (Abby Lee) writes: I've created the following array and want to be able to process each indivisual object whenever my function is called. Is this best done with a "foreach"? I don't see a foreach in my javascript book...is there another way to step threw an array to process each item?
var trvtps = new Array('autoReim b','airRail','c ar','taxi','lod ge','meals','mi sc');
There are two ways:
---
for (var i = 0; i < trvtps.length; i++) {
var trvtp = trvtps[i];
// something with trvtp.
}
---
and
---
for (var i in trvtps) {
var trvtp = trvtps[i];
// something with trvtp.
}
---
The former is targeted at an array (something with a length and
integer indices) whereas the latter works on any object and
iterates all enumerable properties, not only integer ones.
As long as you haven't added properties to "Object.prototy pe",
"Array.prototyp e" or "trvtps" itself, then only the integer properties
are properties of the array.
If you have an array where not all positions have a value, the
for(...in...) will skip these positions, whereas the incrementing
for loop will access all positions less than the length.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Abby Lee said: I've created the following array and want to be able to process each indivisual object whenever my function is called. Is this best done with a "foreach"? I don't see a foreach in my javascript book...is there another way to step threw an array to process each item?
var trvtps = new Array('autoRei mb','airRail',' car','taxi','lo dge','meals','m isc');
The length attribute of the array tells you how many entries
it contains. They will be numbered from 0 to length-1.
for(var i=0;i<trvtps.le ngth;i++){
alert(trvtps[i]);
}
Abby Lee wrote: I've created the following array and want to be able to process each indivisual object whenever my function is called. Is this best done with a "foreach"? I don't see a foreach in my javascript book...is there another way to step threw an array to process each item?
var trvtps = new Array('autoReim b','airRail','c ar','taxi','lod ge','meals','mi sc');
t=trvtps.length ;
while(t--){myProcessFunc tion(trvtps[t])}
Mick
Mick White wrote on 09 sep 2004 in comp.lang.javas cript: t=trvtps.length ; while(t--){myProcessFunc tion(trvtps[t])}
var t=0;
while(t<trvtps. length)
myProcessFuncti on(trvtps[t++])
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)
Evertjan. wrote: Mick White wrote on 09 sep 2004 in comp.lang.javas cript:
t=trvtps.leng th; while(t--){myProcessFunc tion(trvtps[t])}
var t=0; while(t<trvtps. length) myProcessFuncti on(trvtps[t++])
Both approaches work equally well. Did you try both?
Mick
Mick White wrote on 09 sep 2004 in comp.lang.javas cript: Evertjan. wrote:
Mick White wrote on 09 sep 2004 in comp.lang.javas cript:
t=trvtps.len gth; while(t--){myProcessFunc tion(trvtps[t])}
var t=0; while(t<trvtps. length) myProcessFuncti on(trvtps[t++]) Both approaches work equally well. Did you try both?
Who are you asking, Mick?
I just like to have my pointers increasing and minimizing superfluous ()
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: c# newbie |
last post by:
When stepping through code, to find where an error is thrown, the problem is
that I have to step threw the statement that causes the error, and if it's
in a class that's instantiated from the main program, then I may miss the
statement that causes the error.
How can I get the debugger to stop right at the statement that causes the
error.
|
by: David Lozzi |
last post by:
Hello,
I'm receving the following on my webserver (Windows 2003 Server SP1)
Event ID: 5
Source: Active Server Pages
Error: File /KQShopping/ordercomplete4.asp Script Engine Exception. A ScriptEngine threw exception 'C0000005' in 'IActiveScriptParse::ParseScriptText()' from 'CActiveScriptEngine::AddScriptlet()'..
Event ID: 5
Source: Active Server Pages
|
by: pinaki_m77 |
last post by:
Hi, I am trying to debug a C++ program using Microsoft VC++ IDE. The
program loads a dynamic link library (dll) and later makes calls to
functions inside this dll. I want to step inside the code of this dll.
Is that possible to do? Because currently what is happening is, even if
I try to step inside the function in the dll (by F11 key), it is
stepping over the whole function (like F10 does).
How can I step inside the dll code? Am I doing...
|
by: David C |
last post by:
I posted this question, and from the replies, I get the impression that
I worded my posting very poorly, so let me try this again.
While debugging and stepping through this foreach loop
foreach(Student s in course.Students)
{
Console.WriteLine(s.StudentID);
}
|
by: stand__sure |
last post by:
Stepping into a stored procedure used to be fairly straight-forward, but
after following the guidance in all 6 or so of the MSDN pages about enabling
debugging of stored procedures in SQL Server 2005 using VS .NET 2005 running
on WinXP Pro (SP2) -- I'm still having no luck.
Remote debugging works fine.
Stepping into a procedure through the IDE (without the calling app running
works fine)
A quick inspection of the attached processes...
| |
by: Aero |
last post by:
Hi,
My window application written in C# is throwing following exception
while connecting to one FTP location
The type initializer for System.Net.Sockets.Socket threw an exception
This exe is working fine on staging environment, (Window 2003) but
after migrating to production environment (Windows 2000), throwing this
exception at
|
by: kamill |
last post by:
i want to make a website that contains admin section and i needed that at a perticular time only one user can enter threw the admin section.. How can i achive this ( threw php)?
|
by: =?Utf-8?B?TWlrZSBPS0M=?= |
last post by:
VB 2003
As I am stepping through code, I want to see a data table in a grid, so I
can easily see the data in the data table. Currently I QuickWatch the data
table, then I have to add ".rows(0)" after the data table name in QuickWatch
Expression field. I then click on ItemArray, and see the first row in an
array. If I want to see the next row, I then have to return to the expression
field in QuickWatch, replace rows(0) with rows(1). This...
|
by: Lyn |
last post by:
Is there a solution to this problem?
While stepping through code (F8) it would sometimes be helpful to observe
changes occurring on the affected form in the Access window. However, the
current form always seems to be behind all of the open forms (including the
Database window) and only small bits of it are visible -- depending on the
sizes and locations of the various forms on the screen.
Is there a way to ensure that the form being...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |