4D v18

collection.countValues( )

Home

 
4D v18
collection.countValues( )

collection.countValues( )  


 

The collection.countValues( ) method returns the number of times value is found in the collection.

You can pass in value:

  • a scalar value (text, number, boolean, date),
  • an object or a collection reference.

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

 
PROPERTIES 

Product: 4D
Theme: Collections

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

 
ARTICLE USAGE

4D Language Reference ( 4D v18)