Skip to content

Array node library

Usages of Array nodes

Array nodes represent function methods like filter, map, find and reduce for JavaScript arrays.

The following listing shows the array nodes and their respective functions:

find node

Find node

The "find" node will return the value of the first element of an array that fulfills the requirements f the included testing function.

reduce node

Reduce node

The "reduce" node reduces an array to a single value. The node will apply a function against an accumulator and each element in the array (from left to right).

map node

Map node

The "map" node modifies an array with the implemented function. As a result you will get a new array.

filter node

Filter node

The "filter" node will return a new array that contains all elements that pass the conditions of the implemented function.

Using array nodes

Example scenario

A simple array is defined with a sine signal wave. The scenario is to filter and map values.

Objective

To filter the elements which are greater than 0 from an array and map them by adding an added value of 100. Also, it is required to display the sine wave generated in the message payload.

Requirements

  • 1 input timestamp node
  • 1 MindSphere generate node
  • 1 array filter node
  • 1 array map node
  • 1 output debug node

Procedure

  1. Configure generated node as shown below:

    Edit generated node

  2. Filter the array filter node with elements greater than 0.

    Edit filter node

    Note

    The function is already defined in the filter node. You just have to add the condition in the "provided code" section.

  3. Configure the array map node with an added value of 100.

    Edit map node

    Note

    The function is already defined in the filter node. You just have to add the condition in the "provided code" section.

  4. Connect all the nodes as shown below:

    Connect all nodes

  5. Inject the input node.

Result

The values are mapped in the objects and the necessary sine wave has also been generated in the message payload:

Output

Any questions left?

Ask the community


Except where otherwise noted, content on this site is licensed under the MindSphere Development License Agreement.


Last update: April 29, 2022