getindex(::AbstractArray, inds...)

..  getindex(A, inds...)

Returns a subset of array ``A`` as specified by ``inds``, where each ``ind`` may be an ``Int``, a ``Range``, or a ``Vector``. See the manual section on :ref:`array indexing <man-array-indexing>` for details.

Examples

julia> arr = [10, 20, 30, 40, 50];
julia> getindex(arr, 3)
30

This example retrieves the value at index 3 from the array arr.

julia> dict = Dict("apple" => 1, "banana" => 2, "orange" => 3);
julia> getindex(dict, "banana")
2

It retrieves the value associated with the key "banana" from the dictionary dict.

julia> matrix = [1 2 3; 4 5 6; 7 8 9];
julia> getindex(matrix, 2, 3)
6

This example retrieves the value at the specified row and column (2, 3) from the matrix.

Common mistake example:

julia> arr = [10, 20, 30, 40, 50];
julia> getindex(arr, 6)
ERROR: BoundsError: attempt to access 5-element Array{Int64,1} at index [6]

In this example, the index provided is out of bounds for the array. It's important to ensure that the index is within the valid range of the collection to avoid such errors. Always check that the index is a valid position in the collection before using getindex.

See Also

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: