Function getClosestIntegerKey

Gets the closest integer key to target in data.

  • Requires map to have numbers as keys, not strings
  • Math.round is used for rounding target.

Examples:

// Assuming numeric keys 1, 2, 3, 4 exist:
getClosestIntegerKey(map, 3); // 3
getClosestIntegerKey(map, 3.1); // 3
getClosestIntegerKey(map, 3.5); // 4
getClosestIntegerKey(map, 3.6); // 4
getClosestIntegerKey(map, 100); // 4
getClosestIntegerKey(map, -100); // 1
  • Parameters

    • data: ReadonlyMap<number, any>

      Map

    • target: number

      Target value

    Returns number