Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Several operators can be applied to objects of any type.

as()

The as() operators coerces objects of one type to be an object of another. The target type is given as a string argument to the operator. The following types are available in KRL:

  • str. Coerce the target to have type string
  • num. Coerce the target to have type number
  • regexp. Coerce the target to have type regular expression
  • trail. Coerce the target to have type trail

For example, the following constructs a string and then turns it into a regular expression that can be used by the replace() operator:

("/q=" + q + "/i").as("regexp")

Not every type can be coerced to another. The following coercions are valid:

  • Strings can be coerced to numbers and regular expressions.
  • Numbers can be coerced to strings.
  • Regular expressions can be coerced to strings.
  • Trails can be coerced to arrays.

isnull()

The isnull() operator returns true of the object is null (undefined) and false otherwise.

klog()

The klog() operator writes an optional message, given as a string argument, and the value of the object to the debug log. 

x = some_arr.filter(function(x){x == 5}).klog("Value after filter: ").head();

 

typeof()

The typeof()operator returns the type of the object to which it is applied. For example:

nums = [1, 2, 3]
nums_type = nums.typeof() // nums_type = "array"
  • No labels