This is done in two ways:
* It mixes in the Enumerable module, which brings a ton of methods in already.
* It adds quite a few extra methods, which are documented in this section.
Using Iterators: Prototype uses java like iterator in JavaScript
myArray.each(function(item) {
// Your code working on item here...
});
Methods | Description |
Clears the array (makes it empty). | |
Returns a duplicate of the array, leaving the original array intact. | |
Returns a new version of the array, without any null/undefined values. | |
Iterates over the array in ascending numerical index order. | |
Returns the first item in the array, or undefined if the array is empty. | |
Returns a "flat" (one-dimensional) version of the array. | |
Clones an existing array or creates a new one from an array-like collection. | |
Check if the string is 'blank', meaning either empty or containing only whitespace. | |
Returns the debug-oriented string representation of an array. | |
Returns the last item in the array, or undefined if the array is empty. | |
Reduces arrays: one-element arrays are turned into their unique element, while multiple-element arrays are returned untouched. | |
Returns the reversed version of the array. By default, directly reverses the original. If inline is set to false, uses a clone of the original array. | |
Returns the size of the array. | |
This is just a local optimization of the mixed-in toArray from Enumerable. | |
Returns a JSON string. | |
Produces a duplicate-free version of an array. If no duplicates are found, the original array is returned. | |
Produces a new version of the array that does not contain any of the specified values. |
No comments:
Post a Comment