json.count: Difference between revisions
Jump to navigation
Jump to search
(New page: {{MacroFunction |name=json.count |version=1.3b53 |description= Returns the number of occurrences of a value in a JSON Array. If the value does not occur in the JSON Array then {{co...) |
No edit summary |
||
(6 intermediate revisions by 5 users not shown) | |||
Line 3: | Line 3: | ||
|version=1.3b53 | |version=1.3b53 | ||
|description= | |description= | ||
Returns the number of occurrences of a value in a [[JSON Array]]. If the value does | Returns the number of occurrences of a value in a [[JSON Array]]. If the value does not occur in the [[JSON Array]] then {{code|0}} is returned. The index for the [[JSON Array]] starts at {{code|0}}. | ||
not occur in the [[JSON Array]] then {{code| | |||
|usage= | |usage= | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
json.count(array, value)] | |||
</ | </syntaxhighlight> | ||
<syntaxhighlight lang="mtmacro" line> | |||
< | json.count(array, value, start)] | ||
</syntaxhighlight> | |||
</ | |||
'''Parameters''' | '''Parameters''' | ||
{{param|array|The [[JSON Array]] to search.}} | |||
{{param|value|The value to count the occurrences of.}} | |||
{{param|start|The index to start searching from, if not specified it defaults to {{code|0}}.}} | |||
|example= | |example= | ||
< | Find the number of occurrences of {{code|1}}: | ||
<syntaxhighlight lang="mtmacro" line> | |||
[r: json.count("[1,2,3,1,1,3]", 1)] | [r: json.count("[1,2,3,1,1,3]", 1)] | ||
</syntaxhighlight> | |||
Returns {{code|3}} | |||
Find the number of occurrences of {{code|1}}, starting at index {{code|1}}: | |||
<syntaxhighlight lang="mtmacro" line> | |||
[r: json.count("[1,2,3,1,1,3]", 1, 1)] | [r: json.count("[1,2,3,1,1,3]", 1, 1)] | ||
</ | </syntaxhighlight> | ||
Returns {{code|2}} | |||
|also= | |||
{{func|json.contains}} | |||
}} | }} | ||
[[Category:JSON Function]] | [[Category:JSON Function]] |
Latest revision as of 23:59, 15 March 2023
json.count() Function
• Introduced in version 1.3b53
Returns the number of occurrences of a value in a JSON Array. If the value does not occur in the JSON Array then
0
is returned. The index for the JSON Array starts at 0
.Usage
json.count(array, value)]
json.count(array, value, start)]
Parameters
array
- The JSON Array to search.value
- The value to count the occurrences of.start
- The index to start searching from, if not specified it defaults to0
.
Example
Find the number of occurrences of
Returns
1
:
[r: json.count("[1,2,3,1,1,3]", 1)]
Returns 3
Find the number of occurrences of 1
, starting at index 1
:
[r: json.count("[1,2,3,1,1,3]", 1, 1)]
2