json.removeFirst: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Added comparison between difference and removeFirst. Formatting.)
No edit summary
 
(6 intermediate revisions by 4 users not shown)
Line 4: Line 4:
|trusted=false
|trusted=false
|version=1.4.0.3
|version=1.4.0.3
|description:Is similar to json.difference() but will only remove the first occurrence of match.
|description=
Is similar to {{func|json.difference}} but will only remove the first occurrence of a match.


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
json.removeFirst(array1, array2)
json.removeFirst(array1, array2)
</source>
</syntaxhighlight>


'''Parameters'''
'''Parameters'''
Line 15: Line 16:
{{param|array2|A JSON array.}}
{{param|array2|A JSON array.}}


Compares the 2nd array with the first array and removes the first element from the first array matching an element in the second.
Compares the two arrays and removes the first element from the first array matching an element in the second.


|examples= <source lang="mtmacro" line>
|examples=
<syntaxhighlight lang="mtmacro" line>
[json.removeFirst('[2,2,4,5,6,6,4]', '[2,6]')]
[json.removeFirst('[2,2,4,5,6,6,4]', '[2,6]')]
</source>
</syntaxhighlight>
'''Outputs:
'''Outputs:'''
  [2,4,5,6,4]
<pre> [2,4,5,6,4]</pre>
Difference between {{func|json.removeFirst}} and {{func|json.difference}}.
Difference between {{func|json.removeFirst}} and {{func|json.difference}}.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: a1 = '[1,2,2,2,3,3,4,5,6,6]']
[h: a1 = '[1,2,2,2,3,3,4,5,6,6]']
[h: a2 = '[2,4,6]']
[h: a2 = '[2,4,6]']
Line 30: Line 32:
[h: a1 = '[1,2,2,2,3,3,4,5,6,6]']
[h: a1 = '[1,2,2,2,3,3,4,5,6,6]']
[r: json.removeFirst(a1,a2)]
[r: json.removeFirst(a1,a2)]
</source>
</syntaxhighlight>
'''Outputs:
'''Outputs:'''
  [1,3,5]
<pre> [1,3,5]
[1,2,2,3,3,5,6]
  [1,2,2,3,3,5,6]</pre>
 
|also=
|also=
[[Introduction to JSON Datatypes ]], {{func|json.difference}}
[[Introduction to JSON Datatypes ]], {{func|json.difference}}
[[Category:JSON Function]]
[[Category:JSON Function]]
}}
}}

Latest revision as of 23:59, 15 March 2023

json.removeFirst() Function

Introduced in version 1.4.0.3
Is similar to json.difference() but will only remove the first occurrence of a match.

Usage

json.removeFirst(array1, array2)

Parameters

  • array1 - A JSON array.
  • array2 - A JSON array.

Compares the two arrays and removes the first element from the first array matching an element in the second.

Examples

[json.removeFirst('[2,2,4,5,6,6,4]', '[2,6]')]

Outputs:

  [2,4,5,6,4]

Difference between json.removeFirst() and json.difference().

[h: a1 = '[1,2,2,2,3,3,4,5,6,6]']
[h: a2 = '[2,4,6]']
[r: json.difference(a1,a2)]
<!-- a1 has been modified - reset -->
[h: a1 = '[1,2,2,2,3,3,4,5,6,6]']
[r: json.removeFirst(a1,a2)]

Outputs:

  [1,3,5]
  [1,2,2,3,3,5,6]

See Also