宜搭开发包
    正在准备搜索索引...

    类 CountMap<T>

    计数图

    • 适用于需要统计某些键出现次数的场景
    • 可选地关联一个对象,便于在统计的同时存储相关数据
    • 提供静态方法 from 从键数组或键-对象对数组创建实例,简化初始化过程
    • 提供 count 方法对指定键进行计数,并可关联存储对象
    • 提供 getCount 方法获取指定键的计数值,若键不存在则返回 0
    • 提供 getObject 方法获取指定键关联的对象,若键不存在或未关联对象则返回 undefined

    类型参数

    • T

    层级

    • Map<string, { count: number; object?: T }>
      • CountMap
    索引

    构造函数

    • 类型参数

      • T

      参数

      • 可选entries: readonly (readonly [string, { count: number; object?: T }])[] | null

      返回 CountMap<T>

    • 类型参数

      • T

      参数

      • 可选iterable: Iterable<readonly [string, { count: number; object?: T }], any, any> | null

      返回 CountMap<T>

    属性

    "[toStringTag]": string
    size: number

    the number of elements in the Map.

    "[species]": MapConstructor

    方法

    • Returns an iterable of entries in the map.

      返回 MapIterator<[string, { count: number; object?: T }]>

    • Removes all elements from the Map.

      返回 void

    • 对指定键进行计数,若提供了对象则关联存储

      参数

      • key: string

        需要计数的键

      • 可选object: T

        可选的关联对象,在第一次计数时存储,后续计数会覆盖该对象

      返回 void

    • 参数

      • key: string

      返回 boolean

      true if an element in the Map existed and has been removed, or false if the element does not exist.

    • Returns an iterable of key, value pairs for every entry in the map.

      返回 MapIterator<[string, { count: number; object?: T }]>

    • Executes a provided function once per each key/value pair in the Map, in insertion order.

      参数

      • callbackfn: (
            value: { count: number; object?: T },
            key: string,
            map: Map<string, { count: number; object?: T }>,
        ) => void
      • 可选thisArg: any

      返回 void

    • Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.

      参数

      • key: string

      返回 { count: number; object?: T } | undefined

      Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.

    • 获取指定键的计数值,若键不存在则返回 0

      参数

      • key: string

        需要查询的键

      返回 number

    • 获取指定键关联的对象,若键不存在或未关联对象则返回 undefined

      参数

      • key: string

        需要查询的键

      返回 T | undefined

    • 参数

      • key: string

      返回 boolean

      boolean indicating whether an element with the specified key exists or not.

    • Returns an iterable of keys in the map

      返回 MapIterator<string>

    • Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.

      参数

      • key: string
      • value: { count: number; object?: T }

      返回 this

    • Returns an iterable of values in the map

      返回 MapIterator<{ count: number; object?: T }>

    • 从给定的键数组或键-对象对数组创建一个新的 CountMap 实例

      类型参数

      • T

      参数

      • keysOrEntries: string[] | [string, T][]

        需要统计的键数组,或包含键-对象对的数组

      返回 CountMap<T>

    • Groups members of an iterable according to the return value of the passed callback.

      类型参数

      • K
      • T

      参数

      • items: Iterable<T>

        An iterable.

      • keySelector: (item: T, index: number) => K

        A callback which will be invoked for each item in items.

      返回 Map<K, T[]>