json.indexOf

From MapToolDoc
Jump to: navigation, search

json.indexOf() Function

Introduced in version 1.3b53

Returns the index of the first occurrence of a value in the JSON Array. If the value does not exist in the JSON Array then -1 is returned. All JSON Array indexes start at 0.

Usage

  1. json.indexOf(array, value)
  1. json.indexOf(array, value, start)

Parameters

  • array - The JSON Array to search.
  • value - The value to find the index of in the JSON Array.
  • start - The index to start searching from, if not specified it defaults to 0.

Examples

Find the index of the first occurrence of 1:

  1. [r: json.indexOf("[1,2,3,1,1,3]", 1)]

Returns: 0

Find the index of the first occurrence of 1, starting at index 1:

  1. [r: json.count("[1,2,3,1,1,3]", 1, 1)]

Returns: 3

Find the index of the first occurrence of 2, starting at index 2:

  1. [r: json.count("[1,2,3,1,1,3]", 2, 2)]

Returns: -1

See Also

json.count()