[MonkeyScript] [TitleIndex] [WordIndex

   1 /* Iteration */
   2 // Method calls
   3 array.forEach(function(item, index) {
   4   ...
   5 });
   6 
   7 // for each loop (while bad in the browser, our iterator makes this clean code possible server-side)
   8 for each( let item in array ) doStuff(item);
   9 
  10 array.remove('Foo'); // Remove a string === 'Foo' from the array
  11 array.remove('Foo', true); // Second argument forces remove to make sure all 'Foo' strings are removed
  12 
  13 array.has(item); // Check if an item exists inside of an array
  14 
  15 array.diff(anotherArray); // return items in this array that are not in the other array
  16 array.intersect(anotherArray); // return items which are in both arrays
  17 
  18 array.unique(); // return an array with all duplicate items removed
  19 array.shuffle(); // shuffle the order of the array
  20 array.rand(); // return a random item from the array
  21 
  22 array.item(i); // same as array[i]; This is here to match up with Collection API's like those in the DOM
  23 
  24 // WARNING: These getters will not work until [bug]() is fixed.
  25 array.first;  // Named shortcuts for getting the first three items in the array
  26 array.second;
  27 array.third;
  28 array.last;   // Shortcut to get the last item in the array.
  29               // (Useful in chains to avoid the need to temporarily store an array so you can use arr.length);
  30 
  31 array.top; // Alias for array.last; This is here so use of an array with .push() .pop() .top, makes sense in a stack context
  32 
  33 array.nullLess;  // This array, but void of null and undefined items
  34 array.emptyLess; // This array, but void of null, undefined, and emppty strings
  35 

2010-07-23 04:25