json.intersection: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{stub|Examples of usage, and clearer description.}}
{{MacroFunction
{{MacroFunction
|name=json.intersection
|name=json.intersection
|version=1.3b53
|version=1.3b53
|description=
|description=
Returns a [[JSON Array]] with the intersection of all of the [[JSON Object]] keys or [[JSON Array]] values.  An 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 {{func|getTokens}}.
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 {{func|getTokens}}.


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
json.intersection(array, array, ...)
json.intersection(array, array, ...)
</source>
</syntaxhighlight>
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
json.intersection(object, object, ...)
json.intersection(object, object, ...)
</source>
</syntaxhighlight>
'''Parameters'''
'''Parameters'''
{{param|array|A [[JSON Array]] used in the intersection.}}
{{param|array|A [[JSON Array]] used in the intersection.}}
Line 18: Line 19:


|examples=
|examples=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
   [h: array1 = json.append("",1,2,3,4)]
   [h: array1 = json.append("",1,2,3,4)]
   [h: array2 = json.append("",3,4,5,6)]
   [h: array2 = json.append("",3,4,5,6)]
   [r: json.intersection(array1,array2)]
   [r: json.intersection(array1,array2)]
</source>
</syntaxhighlight>


Returns
Returns:
  "[3,4]"
  "[3,4]"






<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
   [h: arrayOfSelectedNames = getSelectedNames("json")]
   [h: arrayOfSelectedNames = getSelectedNames("json")]
   [h: arrayOfNamesOnMap = getTokenNames("json")]
   [h: arrayOfNamesOnMap = getTokenNames("json")]
   [r: json.intersection(arrayOfSelectedNames,arrayOfNamesOnMap)]
   [r: json.intersection(arrayOfSelectedNames,arrayOfNamesOnMap)]
</source>
</syntaxhighlight>


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


Returns
Returns:
  ["Alexander","Josh"]
  ["Alexander","Josh"]



Latest revision as of 17:42, 15 March 2023

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

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

Parameters

Examples

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

Returns:

"[3,4]"


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

Input:

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

Returns:

["Alexander","Josh"]

See Also