JavaScript Arrays
Terminology
Array.prototype.forEach(<callbackFn>,<this>) ¶ Execute a provided function once per array element.
Array.prototype.map(<callback>) ¶ Use a callback function to transform an array into another array.
Array.prototype.reduce(<callbackFn>,<initialValue>) ¶ Apply a function against an accumulator and each value of the array (from left-to-right) to reduce it to a single value.
Array.prototype.sort(<comparator()>) ¶ Sorts the elements of an array in place using an optional comparator function and returns the array.
Facts, Thoughts and Opinions
Array.prototype.distinct()
An algorithm to extract the distinct values from an array.
var index = {}, distinct = [], i, datum; for (i = 0; i < this.length; i++) { datum = this[i]; // modify this as needed if (!index[datum]) { index[datum] = true; distinct.push(datum); } } return distinct;
Select random element from array (JavaScript)
value = myArray[Math.floor(Math.random() * myArray.length)];
Images
[[/div]]
- Subtopics
- Writings
Sources & Bookmarks
Name/Link | ¶ | Date |
---|---|---|
JavaScript Array (Mozilla) | ¶ | 2015-03 |
Javascript Arrays | ¶ | 2014-04-29 |