Method Array.pad
Pad an array to a given size with a given value
-
Syntax
Array Array.pad(Number size , Mixed value )
This function will return a copy of the array padded to lengthsizewith valuevalue. Ifsizeis less than or equal to the length of the array a copy of the array is returned. Ifsizeis negative the array is padded from the left. If positive it is padded from the right. -
Parameters
Number size- The size you want the resulting array to be.
Mixed value- The value to insert when padding.
- Return value The new array padded to the specified size with the specified value.
-
Examples
- To initialize a 200x100 two-dimensional array so that all elements are 0
// Define first array with 100 elements of value 0 var b = [].pad(100,0); // Define a new array with 200 elements all having the value of an array b var a = [].pad(200,b);
-
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.
