This link has been bookmarked by 72 people . It was first bookmarked on 10 Sep 2008, by Webtwo Dozent.
-
06 May 12
-
04 Jul 10
-
22 Jun 10
Pedro ÂngeloWhy a re-introduction? Because JavaScript has a reasonable claim to being the world's most misunderstood programming language. While often derided as a toy, beneath its deceptive simplicity lie some powerful language features.
-
01 Dec 08
-
15 Oct 08
-
10 Oct 08
-
Why a re-introduction? Because JavaScript has a reasonable claim to being the world's most misunderstood programming language. While often derided as a toy, beneath its deceptive simplicity lie some powerful language features. 2005 has seen the launch of a number of high-profile JavaScript applications, showing that deeper knowledge of this technology is an important skill for any web developer.
-
-
07 Oct 08
-
21 Sep 08
-
If you take the above into account, you can iterate over an array using the following:
for (var i = 0; i < a.length; i++) { // Do something with a[i] }This is slightly inefficient as you are looking up the length property once every loop. An improvement is this:
for (var i = 0, len = a.length; i < len; i++) { // Do something with a[i] }An even nicer idiom is:
for (var i = 0, item; item = a[i]; i++) { // Do something with item }Here we are setting up two variables. The assignment in the middle part of the
forloop is also tested for truthfulness - if it succeeds, the loop continues. Sinceiis incremented each time, items from the array will be assigned to item in sequential order. The loop stops when a "falsy" item is found (such asundefined).Note that this trick should only be used for arrays which you know do not contain "falsy" values (arrays of objects or DOM nodes for example). If you are iterating over numeric data that might include a 0 or string data that might include the empty string you should use the
i, jidiom instead.Another way to iterate is to use the
for...inloop. Note that if someone added new properties toArray.prototype, they will also be iterated over by this loop:for (var i in a) { // Do something with a[i] }
-
-
18 Sep 08
-
16 Sep 08
-
15 Sep 08
-
13 Sep 08
-
12 Sep 08
Melanie KWhy a re-introduction? Because JavaScript has a reasonable claim to being the world's most misunderstood programming language. While often derided as a toy, beneath its deceptive simplicity lie some powerful language features. 2005 has seen the launch of
-
Andrew WhiteWhy a re-introduction? Because JavaScript has a reasonable claim to being the world's most misunderstood programming language. While often derided as a toy, beneath its deceptive simplicity lie some powerful language features. 2005 has seen the launch of
-
11 Sep 08
-
10 Sep 08
-
David Feld"Unlike most programming languages, the JavaScript language has no concept of input or output. It is designed to run as a scripting language in a host environment, and it is up to the host environment to provide mechanisms for communicating with the outsi
-
09 Sep 08
-
03 Sep 08
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.