filter Summary Returns a new array with all elements of the original array that pass the specified condition. Signatures Click on a signature to select it and view its documentation. public T[] filter(bool(T currentValue) callback) public T[] filter(bool(T currentValue, int index) callback) public T[] filter(bool(T currentValue, int index, T[] array) callback) Usage public T[] filter(bool(T currentValue) callback) public T[] filter(bool(T currentValue, int index) callback) public T[] filter(bool(T currentValue, int index, T[] array) callback) Returns A new array with all elements of the original array that pass the specified condition. A new array with all elements of the original array that pass the specified condition. A new array with all elements of the original array that pass the specified condition. Parameters callback A function which provides the test logic. Parameters callback A function which provides the test logic. Parameters callback A function which provides the test logic. Description Returns a new array with all elements of the original array that pass the specified condition. This method was standardized in ECMAScript 5 for JavaScript. For web browsers that do not support ECMAScript 5, JS++ will provide a polyfill for this method only if it is used. Returns a new array with all elements of the original array that pass the specified condition. This method was standardized in ECMAScript 5 for JavaScript. For web browsers that do not support ECMAScript 5, JS++ will provide a polyfill for this method only if it is used. Returns a new array with all elements of the original array that pass the specified condition. This method was standardized in ECMAScript 5 for JavaScript. For web browsers that do not support ECMAScript 5, JS++ will provide a polyfill for this method only if it is used. Examples Basic Usage 1234567import System; int[] numbers = [ 2, 3, 4, 5, 6, 8, 10 ];int[] oddNumbers = numbers.filter(bool(int currentValue) { return currentValue % 2 == 1;});Console.log(oddNumbers.toString()); Basic Usage 1234567import System; int[] numbers = [ 2, 3, 4, 5, 6, 8, 10 ];int[] oddNumbers = numbers.filter(bool(int currentValue) { return currentValue % 2 == 1;});Console.log(oddNumbers.toString()); Logging the current array index on each iteration 12345678import System; int[] numbers = [ 2, 3, 4, 5, 6, 8, 10 ];int[] oddNumbers = numbers.filter(bool(int currentValue, int index) { Console.log("index: " + index.toString()); return currentValue % 2 == 1;});Console.log(oddNumbers.toString()); Basic Usage 1234567import System; int[] numbers = [ 2, 3, 4, 5, 6, 8, 10 ];int[] oddNumbers = numbers.filter(bool(int currentValue) { return currentValue % 2 == 1;});Console.log(oddNumbers.toString()); Access original array inside callback 123456789import System;import System.Assert; int[] numbers = [ 2, 3, 4, 5, 6, 8, 10 ];int[] oddNumbers = numbers.filter(bool(int currentValue, int index, int[] array) { assert(currentValue == array[index]); return array[index] % 2 == 1;});Console.log(oddNumbers.toString()); Share HTML | BBCode | Direct Link