This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
collection.countValues( )
|
collection.countValues ( value {; propertyPath} ) -> Function result | ||||||||
Parameter | Type | Description | ||||||
value | Text, Number, Boolean, Date, Object, Collection |
![]() |
Value to count | |||||
propertyPath | Text |
![]() |
Object property path for values to count | |||||
Function result | Longint |
![]() |
Number of occurrences of the value | |||||
The collection.countValues( ) method returns the number of times value is found in the collection.
You can pass in value:
For an element to be found, the type of value must be equivalent to the type of the element; the method uses the equality operator.
The optional propertyPath parameter allows you to count values inside a collection of objects: pass in propertyPath the path of the property whose values you want to count.
Note: This method does not modify the original collection.
C_COLLECTION($col)
C_LONGINT($vCount)
$col:=New collection(1;2;5;5;5;3;6;4)
$vCount:=$col.countValues(5) // $vCount=3
C_COLLECTION($col)
C_LONGINT($vCount)
$col:=New collection
$col.push(New object("name";"Smith";"age";5))
$col.push(New object("name";"Wesson";"age";2))
$col.push(New object("name";"Jones";"age";3))
$col.push(New object("name";"Henry";"age";4))
$col.push(New object("name";"Gross";"age";5))
$vCount:=$col.countValues(5;"age") //$vCount=2
C_COLLECTION($numbers)
C_COLLECTION($letters)
C_LONGINT($vCount)
$letters:=New collection("a";"b";"c")
$numbers:=New collection(1;2;$letters;3;4;5)
$vCount:=$numbers.countValues($letters) //$vCount=1
Product: 4D
Theme: Collections
Number:
705252
Created: 4D v16 R6
4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)