The following functions can be used to manipulate and retrieve details from objects and arrays.

These should be written in the following formats:

Click each function name in the table below for more details of it, with examples.

Functions

Function

Description

.some()

Returns true if "some" of the values are true, else returns false.

.filter()

Returns the array with values filtered out that match the filter input.

.forEach()

Returns a value for each separate element in an array after executing the provided function once per array element.

.map()

Returns a new array with the results of calling a provided function on every element within this array.

.every()

Returns true if all elements in the array passed the input parameters (all where true).

CreateFunction

Understanding CreateFunction() might seem hard at first, but once you play with some examples it can be easy to understand. CreateFunction allows the user to define and create there own functions which can be used on the Functions seen above. The CreateFunction() requires an arguments string, and a formula string. These are formatted like so: CreateFunction("Arguments","Formula") The arguments is what to pass into the function, when using functions like forEach and map, you may be required to pass in an "array" and an "index" argument, this is for the internal processing used in the forEach and map functions. All the functions do however require one argument. This argument is referred too as the "currentValue". This is because this indicates the current value we're handling from the array the function is being used on. Imagine we have an array of 4 numbers: a=[1,2,3,4] to use the functions above on this array it will need to process each number (1,2,3 and 4). While doing so, this number is referred too as the currentValue. The example below shows how the currentValue is set.

As you can see in this example, the currentValue is an argument, it is also used in the formula to complete a process. Expanding on this function, we could use forEach on an array Arr=[1,2,3,4] to add the elements the existing array to a new array called Arr2.

The output of this would be:

In the formula section of this CreateFunction we've put: "Arr2.push(currentValue)". This is a simple command telling it to push the currentValue to the array Arr2. This now means we have two totally identical arrays that are totally separate from one another.

some

Usage: .some(CreateFunction("input","handling"))

the .some() function requires at least 1 input. This input is how you'll reference the current value (elements of the array you're running this function against). .some() is a boolean check to see if at least one or more elements in an array return true. If all are false this will return false, but if at least one is true, the result will be true.

Example:

Result:

filter

Usage: .filter(CreateFunction("input","handling"))

the .filter() function requires at least 1 input. This input is how you'll reference the current value (elements of the array you're running this function against). .filter() returns an array with the values from the input array. But only if these values passed the filter function entered. If one does not pass, that one will not exist in the new array.

Example:

Result:

forEach

Usage: .forEach(CreateFunction("input,Index,Array","handling"))

the .forEach() function requires at least 3 inputs. This consists of an Array, and Index and the input current value. The index and array are needed for the function handling. .forEach() returns an array with the values from the input array. But only if these values passed the filter function entered. If one does not pass, that one will not exist in the new array. .forEach Returns a value for each separate element in the array that you've passed in after executing the provided function (CreateFunction) once per array element.

Example:

Result:

map

Usage: .map(CreateFunction("input,Index,Array","handling"))

the .map() function requires at least 3 inputs. This consists of an Array, and Index and the input current value. The index and array are needed for the function handling. The .map() function will create a new array consisting of the results of running the CreateFunction on each element within the previous array. Every value in the previous array will run the CreateFunction. There output is then appended to the new array at the same index it was at in the original array.

Example:

Result:

every

Usage: .map(CreateFunction("input,Index,Array","handling"))

the .every() function requires at least 1 input. This is the current value within the array. the .every() function will return true or false depending on the output of every array element after processing through the function. If just one of the elements returns false, this will return false, but if all returned true, then this will be true.

Example:

Result:


CategoryFunctions

CreateFunction (last edited 2015-09-08 12:12:11 by LKD70)