endof(collection) -> Integer

Returns the last index of the collection.

julia> endof([1,2,4])


  1. Get the last index of an array:

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

    This example returns the last index of the array arr, which is 5.

  2. Find the last index of a string:

    julia> text = "Hello, World!";
    julia> endof(text)

    It returns the last index of the string text, which is 13.

  3. Calculate the last index of a range:
    julia> range = 1:10;
    julia> endof(range)

    It determines the last index of the range range, which is 10.

Common mistake example:

julia> nums = [5, 10, 15, 20];
julia> endof(nums, 2)
ERROR: MethodError: no method matching endof(::Array{Int64,1}, ::Int64)

In this example, the endof function is called with more arguments than expected. The correct usage is endof(collection) to retrieve the last index. Be careful to provide only the collection and not additional arguments.

See Also

append!, delete!, deleteat!, empty!, endof, filter, filter!, gc, get!, getkey, haskey, insert!, isempty, keys, map, map!, merge, merge!, pop!, prepend!, push!, reduce, resize!, shift!, splice!, unshift!, values,

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

Checking you are not a robot: