Method Array.remove
Remove elements from an array
-
Syntax
undefined Array.remove([ Function f ])
This function will remove any elements from the array which satisfy the conditions in the user provided functionf. If no function i passed undefined and null values are removed.
The functionfshould either return true if the element should be removed or false if it should not be removed. -
Parameters
Function f(Optional)- The function which decides whether an element is removed or not.
-
Return value
No explicit return value. Default value of
undefinedis returned. -
Examples
- To remove all numbers greater than 10
// Define array var a = new Array(20,3,5,10,3,19,24,0); // Define a function which returns true if argument 0 is greater than 10 function greaterThan10(i) { if (i > 10) return true; else return false; } // Output is (3,5,10,3,0) a.remove(greaterThan10);- To remove all string with a length less than 5
// Define array a = new Array('abc','abcdef','a','abcde'); // Define a function which returns true if argument 0 is a string // with length less than 5 function lengthLessThan5(i) { if (i.length < 5) return true; else return false; } // Output is ('abcdef','abcde') a.remove(lengthLessThan5);
-
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.
