RandomAccessCollection

public extension RandomAccessCollection where Element: Equatable

Available where Element: Equatable

  • SwifterSwift: All indices of specified item.

       [1, 2, 2, 3, 4, 2, 5].indices(of 2) -> [1, 2, 5]
       [1.2, 2.3, 4.5, 3.4, 4.5].indices(of 2.3) -> [1]
       ["h", "e", "l", "l", "o"].indices(of "l") -> [2, 3]
    

    Declaration

    Swift

    func indices(of item: Element) -> [Index]

    Parameters

    item

    item to check.

    Return Value

    an array with all indices of the given item.