Method Array.mapMethod
Apply a method to all members of an array
-
Syntax
undefined Array.mapMethod(Function m , [ Mixed a0 ... an ])
This method will apply the methodmto each member of the array. Any extra arguments are passed along to the method. -
Parameters
Function m- The method you wish to apply
Mixed a0 ... an(Optional)- Optional arguments to be passed to the method
m
-
Return value
No explicit return value. Default value of
undefinedis returned. -
Examples
- To check all members of an array is a number below 10
// Define array var a = [1,2,3,4]; // Define function function checkNumber(n) { if (this.constructor != Number || this > n) throw new Error('Member not a number or greater than ' + n); } // Apply method to members a.mapMethod(checkNumber,10);
-
Download
Source
Unless otherwise noted all code in the JSLab Standard Library is licensed as GPLv3. See http://www.gnu.org/licenses/gpl.html for the entire license.
