json.removeFirst: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 18: Line 18:
Compares the two arrays 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=
<source 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>
</source>
'''Outputs:
'''Outputs:'''
[2,4,5,6,4]
  [2,4,5,6,4]
Difference between {{func|json.removeFirst}} and {{func|json.difference}}.
Difference between {{func|json.removeFirst}} and {{func|json.difference}}.
<source lang="mtmacro" line>
<source lang="mtmacro" line>
Line 32: Line 33:
[r: json.removeFirst(a1,a2)]
[r: json.removeFirst(a1,a2)]
</source>
</source>
'''Outputs:
'''Outputs:'''
[1,3,5]
  [1,3,5]
[1,2,2,3,3,5,6]
  [1,2,2,3,3,5,6]


|also=
|also=

Revision as of 03:43, 1 March 2019

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