This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v19.8
collection.countValues( )

collection.countValues( ) 


 

collection.countValues ( value {; propertyPath} ) -> Function result 
Parameter Type   Description
value  Text, Number, Boolean, Date, Object, Collection in Value to count
propertyPath  Text in Object property path for values to count
Function result  Longint in 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:

  • 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
Number: 705252

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v16 R6

 
ARTICLE USAGE

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)