From Noisebridge
< JavaScript
Revision as of 13:04, 29 October 2013 by Garrett (Talk | contribs)

Jump to: navigation, search

Array methods are used or hand-rolled (as a fallback in a lot of javascript libraries, such as jQuery and Underscore, as discussed tonight.

EcmaScript 5 has standardized methods that were introduced as "Array Extras" in Firefox 1.5. These neat methods are present in all modern browsers, but can have a noticeable performance impact for lengthy arrays, particularly on limited devices.

The normative reference for these methods is the EcmaScript 5.1 specification, a mature, official standard. Each method description has an overview of what it does, followed by the algorithm.


Here is the link to Array.prototype:

MDC on Array:

It is interesting that these methods can also be used generically on something that is Array-like.

var filter = Array.prototype.filter;"foo",  function (ch) { return ch == "o"; }).join("");

Array-like was proposed as a standard interface (I championed this idea for a while), but was not included. Perhaps it will be, some day.

But for now, it is useful to know that these methods are natively supported in modern browsers.

Assignment 1

Write a function that removes an element from an array.

Assignment 2

Write a function that removes duplicate elements from an array.

Personal tools