INDEX (Array, Index) INDEX (Array; Index)

Array

The array from which an element should be retrieved.

Index

Number Number

The position of the element to return, starting with 1.

Returns

The array element at the given position.

Returns the array element at the given position. INDEX ({ 10, 20, 30 }, 2) INDEX ({ 10; 20; 30 }; 2) returns the second element, 20.

INDEX, MATCH and XMATCH

INDEX is often used together with MATCH and XMATCH to look up values from another array. MATCH and XMATCH are used to find a value in an array and return its position, where the position is then given to INDEX, which returns the array element at that position. Consider this formula:

XMATCH (20, { 10, 20, 30 })
XMATCH (20; { 10; 20; 30 })

The formula above returns 2, because the sought value, 20, is found at the second position in the { 10, 20, 30 }{ 10; 20; 30 } array.

As such, this formula returns 2 if the value of SoughtValue is equal to 1, 4 if it is equal to 2 and 8 if it is equal to 3:

INDEX ({ 2, 4, 8 }, XMATCH (SoughtValue, { 1, 2, 3 }))
INDEX ({ 2; 4; 8 }; XMATCH (SoughtValue; { 1; 2; 3 }))

This XLOOKUP formula is equivalent:

XLOOKUP (SoughtValue, { 1, 2, 3 }, { 2, 4, 8 })
XLOOKUP (SoughtValue; { 1; 2; 3 }; { 2; 4; 8 })

INDEX and SIZE

The SIZE function returns the number of elements in an array. It can be used together with INDEX to return array elements from the end of the array.

This formula returns the second array element:

INDEX (SomeArray, 2)
INDEX (SomeArray; 2)

This formula returns the second to last array element from SomeArray :

INDEX (SomeArray, SIZE (SomeArray) - 1)
INDEX (SomeArray; SIZE (SomeArray) - 1)

Multiple results

Multiple elements can be retrieved at the same time using INDEX, by supplying an array as the second parameter. This formula returns the first and third elements as an array, { 10, 30 }{ 10; 30 }:

INDEX ({ 10, 20, 30 }, { 1, 3 })
INDEX ({ 10; 20; 30 }; { 1; 3 })

Examples

INDEX ({ 10, 20, 30 }, 2)
INDEX ({ 10; 20; 30 }; 2)

Returns the second element, 20.

INDEX ({ 10, 20, 30 }, { 1, 3 })
INDEX ({ 10; 20; 30 }; { 1; 3 })

Returns the first and third elements as an array, { 10, 30 }{ 10; 30 }.

INDEX (SomeArray, SIZE (SomeArray))
INDEX (SomeArray; SIZE (SomeArray))

Returns the last element from SomeArray , using the SIZE function, which returns the number of elements in an array.

INDEX ({ 2, 4, 8 }, XMATCH (SoughtValue, { 1, 2, 3 }))
INDEX ({ 2; 4; 8 }; XMATCH (SoughtValue; { 1; 2; 3 }))

Returns 2 if SoughtValue is equal to 1, 4 if it is equal to 2 and 8 if it is equal to 3.

XLOOKUP (SoughtValue, { 1, 2, 3 }, { 2, 4, 8 })
XLOOKUP (SoughtValue; { 1; 2; 3 }; { 2; 4; 8 })

Returns 2 if SoughtValue is equal to 1, 4 if it is equal to 2 and 8 if it is equal to 3. Combining INDEX and XMATCH is often equivalent to using XLOOKUP.

INDEX (Matrix, RowIndex, ColumnIndex) INDEX (Matrix; RowIndex; ColumnIndex)

Matrix

The two-dimensional array from which an element should be retrieved.

RowIndex

Number Number

The one-based row position of the element to return.

ColumnIndex

Number Number

The one-based column position of the element to return.

Returns

The element at the given row and column position.

Returns the element at the given row and column position in a two-dimensional array. INDEX ({{ 10, 20 }, { 30, 40 }}, 2, 1) INDEX ({{ 10; 20 }; { 30; 40 }}; 2; 1) returns 30, the element in row 2 and column 1.

Examples

INDEX ({ { 10, 20 }, { 30, 40 } }, 2, 1)
INDEX ({ { 10; 20 }; { 30; 40 } }; 2; 1)

Returns 30, the element in row 2 and column 1 of the matrix.

INDEX ({ { 10, 20 }, { 30, 40 } }, 1, 2)
INDEX ({ { 10; 20 }; { 30; 40 } }; 1; 2)

Returns 20, the element in row 1 and column 2 of the matrix.

fxEngine Shell Want this in your own terminal? A standalone version is coming. Get notified.
Loading fxEngine Shell