Skip to main content

Try it Live

Run EventLog examples in the interactive playground

    Sort Order

    Primary: Block Number

    Logs sorted by block number ascending (earliest blocks first):

    Secondary: Log Index

    Within same block, sorted by log index ascending:

    Missing Values

    Logs without blockNumber or logIndex treated as 0:

    Usage Patterns

    Chronological Processing

    Combining with Filtering

    Finding Latest Log

    Finding Earliest Log

    Grouping by Block

    Time-Ordered Event Replay

    Detecting Missing Logs

    Pagination

    Implementation

    Sort algorithm:
    1. Compare block numbers (ascending)
    2. If equal, compare log indices (ascending)
    3. Treat undefined as 0

    Performance

    • Time complexity: O(n log n)
    • Space complexity: O(n) (creates new array)
    • Stable sort: Maintains relative order of equal elements
    For large arrays, sort once and reuse:

    See Also