json.intersection

From MapToolDoc
Jump to: navigation, search

json.intersection() Function

Introduced in version 1.3b53

Returns a JSON Array with the intersection of all of the JSON Object keys or JSON Array values. A value or key only appears in the output if it exists in all input arrays or objects.

This function is useful for removing Token IDs from a saved list which have been deleted from the map by eliminating them using this function, the saved array and getTokens().

Usage

  1. json.intersection(array, array, ...)
  1. json.intersection(object, object, ...)

Parameters

Examples

  1.   [h: array1 = json.append("",1,2,3,4)]
  2.   [h: array2 = json.append("",3,4,5,6)]
  3.   [r: json.intersection(array1,array2)]

Returns:

"[3,4]"


  1.   [h: arrayOfSelectedNames = getSelectedNames("json")]
  2.   [h: arrayOfNamesOnMap = getTokenNames("json")]
  3.   [r: json.intersection(arrayOfSelectedNames,arrayOfNamesOnMap)]

Input:

arrayOfSelectedNames = ["Alexander","Josh"]
arrayOfNamesOnMap = ["Kevin","Josh","Alexander"]

Returns:

["Alexander","Josh"]

See Also

json.difference()