JavaScript Programmer’s (Web site developers) Reference Dec Hex Sym Unicode Description
Friday, August 24th, 2007JavaScript Programmer’s Reference Dec Hex Sym Unicode Description 003 03 ETX u0003
JavaScript Programmer’s Reference Dec Hex Sym Unicode Description 003 03 ETX u0003
A ASCII (Standard) this.length = aSize; for(var index = 0; index
JavaScript Programmer’s Reference Array.valueOf() (Method) Returns the contents of the array converted to a native primitive value. Availability: JavaScript 1.1 JScript 3.0 Internet Explorer 4.0 Netscape 3.0 Property/method value type: String primitive JavaScript syntax: -myObject.valueOf() The primitive value of the receiving object is returned by this method. Because an array is an aggregation of many elements, a simple type conversion is not appropriate. The individual elements are converted to string values and are then concatenated together and returned as a single string primitive value. This applies even if an array comprises a collection of numeric values. See also: valueOf() Array simulation (Definition) A means of simulating arrays in JavaScript. With a constructor, you can simulate arrays by making them from objects and property components. This may be useful if you want to run an array-based script in a very old JavaScript implementation although these days that likelihood is diminishing rapidly. This was necessary in JavaScript version 1.0. Numbered index locations within an Object object could simulate Array objects. Named items simply allocate the next available numbered entry. Thankfully we don’t have to do this anymore. Warnings: . In Netscape 2.02 and MSIE 3.02 you can operate on existing arrays, but you cannot make a new one. . In Netscape 2.02 the array length value does not work properly. Example code: // Simulate an array with an Object object myArray = new Object(); myArray[0] = “One”; myArray[1] = “Two”; // Simulate an array with a constructor function SimArray(aSize) {
A Array.unshift() (Method) Array instance A B C Array.unshift(”X”) Array instance X A B C 125
JavaScript Programmer’s Reference This operates very like the Array.push() method except that items are added to the front of the stack rather than the end of the stack. The items are also pushed in reverse order if several are presented at once. That is to say, the order of presentation is preserved within the array. When the push is completed, the item at the front of the array is returned. The number of items that were added increases the array length. If arrays are presented, they will be pushed on as they are and not flattened. When they are subsequently removed from the stack, they will still be arrays. This method modifies the array in place. The result of this method is the new length of the receiving array after the pushed item has been concatenated onto its front. Example code: // Create an array and test the Array.unshift() method myArray = new Array(”AAA”, “BBB”, “CCC”); document.write(”Array
“) displayArrayAsTable(myArray); document.write(”Array.unshift()
“) document.write(myArray.unshift(”XXX”)) document.write(”
“) document.write(”Array after unshift(’XXX’) call
“) displayArrayAsTable(myArray); // Display an array in a table function displayArrayAsTable(anArray) { myLength = anArray.length; document.write(”
| “); document.write(myIndex); document.write(” | “); document.write(anArray[myIndex]); document.write(” |
A Array.unshift() (Method) Cross-references: ECMA 262 edition 2 section 15.4.4.2 ECMA 262 edition 3 section 15.4.4.2 “A” “B” “C” “D” Array instance 0 1 2 3 “ABCD” “A” “C”"B” “D” Array.unshift() (Method) Push onto a stack whose access is FILO from the start rather than the end. ECMAScript edition 3 JavaScript 1.2 JScript 5.5 Internet Explorer 5.5 Netscape 4.0 Netscape Enterprise Server 3.0 Number primitive -myArray.unshift(someValue, …) someValue A series of values to be pushed onto the stack Availability: Property/method value type: JavaScript syntax: Argument list:
JavaScript Programmer’s Reference Array.toString() (Method) Return a string primitive version of an object. Availability: ECMAScript edition 2 JavaScript 1.1 JScript 3.0 Internet Explorer 4.0 Netscape 3.0 Netscape Enterprise Server 2.0 Opera 3.0 Property/method value type: String primitive JavaScript syntax: -myArray.toString() The elements in the array are converted to strings and are concatenated together to form a larger string. This is functionally identical to using the join() method with no join string argument. If you run the example, it will yield the following: one,2,III This is quite different from what you get if you use the toSource() method, which presents this result: [”one”, 2, “III”] The result of this method is a String primitive version of the array assembled by concatenation. Warnings: . Netscape supports a special conversion mechanism if this method is invoked within a