spacer

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

home / experts / javascript / column26


Changes to the Array Object

Developer News
ActiveState Debuts Open Source Business Suite
Salesforce Offers Visual App Builder
Codesion Steps Out From CVS's Shadow

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


The Network for Technology Professionals

Search:

About Internet.com

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

webref The latest from WebReference.com Browse >
Use Web Caching to Make Your Web Site Faster · Creating an Online Shopping Cart Mechanism in PHP · Log JavaScript Errors Using an AJAX-driven Web Service
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Configuring Granular Settings for a Database Level Audit · The Perils of a Web 2.0 Transition on Your Business Processes · Facebook Redesigns Site —Again — Nears 400M Mark


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

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