Phaser API Documentation

  Version: 

Member of: Phaser.Utils.Array

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

Description:

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.

Parameters:

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.

Returns:
Description:

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

Type:
  • number
  • any
Since: 3.0.0