spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column26


Changes to the Array Object

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

JavaScript 1.3 introduces a number of significant changes to the Array object. Read this page carefully, as there is a good chance you have to modify your code to adapt it to JavaScript 1.3.

The length property of the Array object is now an unsigned, 32-bit integer. Its value is a positive integer and it is less than 2 to the power of 32. The length property in JavaScript 1.2 is a signed integer with value less than 2 to the power of 31.

JavaScript 1.3 reverts to the JavaScript 1.1's array constructing specification. The Array constructor in JavaScript 1.2 constructs a single-element array when you specify a single parameter. When you specify ar = new Array(11) and Language="JavaScript1.2", you will get the single-element array, ar[0] = 11;. In JavaScript 1.3, though, a single-parameter constructor verifies that the argument is a number, converts it to an unsigned, 32-bit integer, and generates an array of the specified size. The length property of the array will be equal to the argument. The initial value of the Array elements will be undefined. Referring back to the example above, when you specify ar = new Array(11) and Language="JavaScript1.3", a new ar array will be generated, with 11 undefined elements. So, to summarize, the following two-line script:

a = new Array(11);
document.write("First element is " + a[0]);

will yield First element is undefined in JavaScript 1.3, First element is 11 in JavaScript 1.2, and First element is undefined in JavaScript 1.1.

The push() method behaves differently in JavaScript 1.3. In JavaScript 1.2, it returns the last element added to the array. In JavaScript 1.3, the push() method returns the new length of the array. The splice() method also changed. In JavaScript 1.2, it returns the element removed, if only one element is removed, and none, if more than one element is removed. In JavaScript 1.3, splice() always returns an array containing the removed elements. If one element is removed, a single-element array is returned.

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Created: September 28, 1998
Revised: September 28, 1998

URL: http://www.webreference.com/js/column26/array.html