Editing JavaScript/Notes/Array
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
In this lesson, I explain what an <code>Array</code> is, properties of Array instances, and methods of <code>Array.prototype</code> that were added in EcmaScript 5. | In this lesson, I explain what an <code>Array</code> is, properties of Array instances, and methods of <code>Array.prototype</code> that were added in EcmaScript 5. | ||
== | == Array Instances == | ||
Array instances also have a special definition for the internal method called <code><nowiki>[[DefineOwnProperty]] ( P, Desc, Throw )</nowiki></code> used for property assignment and a special <code>length</code> property that affects and is affected by the properties in the array. The <code><nowiki>[[Class]]</nowiki></code> internal property value is "Array" ([http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.5 § 15.4.5]). | Array instances also have a special definition for the internal method called <code><nowiki>[[DefineOwnProperty]] ( P, Desc, Throw )</nowiki></code> used for property assignment and a special <code>length</code> property that affects and is affected by the properties in the array. The <code><nowiki>[[Class]]</nowiki></code> internal property value is "Array" ([http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.5 § 15.4.5]). | ||
Array instances inherit properties from the <code>Array prototype</code> ([http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4 §15.4.4]) object. === Length and <nowiki>[[DefineOwnProperty]]</nowiki> === | |||
=== Length and <nowiki>[[DefineOwnProperty]]</nowiki> === | |||
<source lang="javascript"> | <source lang="javascript"> | ||
// length. | // length. | ||
Line 88: | Line 87: | ||
== Assignment 1 Write a function that removes an element from an array. == | == Assignment 1 Write a function that removes an element from an array. == | ||
Write a function that | Write a function that removes an element from an array. | ||
Given: | Given: | ||
Line 94: | Line 93: | ||
var thing = {}, f = function(){}; | var thing = {}, f = function(){}; | ||
var input = [f, [], /foo/, thing, []]; | var input = [f, [], /foo/, thing, []]; | ||
removeElement(input, thing); // [f, [], /foo/, []]; | removeElement(input, thing); // [f, [], /foo/, []]; | ||
</source> | </source> | ||
== Assignment 2 Write a function that removes duplicate numbers from an array. == | == Assignment 2 Write a function that removes duplicate numbers from an array. == | ||
<source lang="javascript"> | <source lang="javascript"> | ||
var input = [1, 2, 3, 1, 0, 1]; | var input = [1, 2, 3, 1, 0, 1]; | ||
var result = | var result = arrayUnique( input ); // [1, 2, 3, 0]; | ||
</source> | </source> | ||
== Assignment 3 Write a function that sorts an array of strings case-insensitively. == | == Assignment 3 Write a function that sorts an array of strings case-insensitively. == | ||
Write a function that sorts an array of strings case-insensitively. | Write a function that sorts an array of strings case-insensitively. | ||