Phaser API Documentation


Member of: Phaser.Utils.Array

<static> FindClosestInSorted(value, array, [key])


Searches a pre-sorted array for the closet value to the given number.

If the key argument is given it will assume the array contains objects that all have the required key property name, and will check for the closest value of those to the given number.


name type arguments description
value number

The value to search for in the array.

array array

The array to search, which must be sorted.

key string <optional>

An optional property key. If specified the array elements property will be checked against value.


The nearest value found in the array, or if a key was given, the nearest object with the matching property value.

  • number
  • any
Since: 3.0.0