# Flatten

The Flatten function Functions are tools that are available in Spreadsheet for processing and analyzing acquisitions or other results. You can add functions to your Spreadsheet job to create tool chains and produce results for specific applications. returns an array that contains all the elements of the specified input arrays. This is also called an array of arrays. The function works as follows:

- Returns all the elements of the inner arrays of a single, nested array, for example [["result1", "result2"], ["data1"]].

- Returns all the elements of the selected input arrays, for example ["result1", "data1"] and ["result2", "data2"].

For example, if the nested input array is [["result1", "result2"], ["data1"]], the function returns an array of ["result1", "result2", "data1"].

Inputs

You can use the Flatten function with two different syntaxes:

- A single argument, which must be an array of arrays: Flatten(Array, ...)

- Multiple arguments, each of which is a separate array: Flatten (Array, Array, ...)

The first syntax allows combining nested arrays from a single cell. The second syntax allows combining arrays from different cells.

Parameter | Description
--- | ---
Array | Refers to an array cell.

Outputs

Returns | Returns an Array that contains all the elements of the specified input arrays.

Combining Flatten and Map Functions

You can use the Flatten and Map functions together with complex nested objects and arrays to get a simple array to work with.

For example, if the input array is [{result:"1", index:["1","2"]}, {result:"2", index:["3"]}], then Flatten(Map(array, "index")) returns just the list of all the indexes, ["1", "2", "3"].

If a Toolchain function returns a result with multiple views, you can use the Flatten and Map functions together to merge the views. This is useful for sorting all the view results.

In the example below, you can see a Toolchain Segmenter result, which produces three different views from three different ROIs. Each view contains one or two blobs. The Flatten(Map(B26, "blobs")) cell returns a single array that contains all four blobs, which you can pass into SortDescending().