ToScript

Creates a JavaScript expression that assigns the input BoxLang value to a JavaScript variable.

This is useful for converting BoxLang values to JavaScript variables in a script. It can convert:

  • Booleans

  • DateTimes

  • Numbers

  • Arrays

  • Queries

  • Strings

  • Structures

Method Signature

ToScript(cfvar=[any], javascriptvar=[string])

Arguments

Argument
Type
Required
Description
Default

cfvar

any

true

The value to convert to a script line; String, DateTimes, Number, Array, Structure or Query

javascriptvar

string

true

The name of the JavaScript variable to assign the result to.

Examples

Multiple to Script Examples

Converts boxlang objects to JavaScript syntax for use

Run Example

Additional Examples

Run Example

RESULT: jsVar = {"1":"boxlang"}; jsVar = ["boxlang"]; Query = {"columns":["name","age"],"data":[["Susi",20]]}; Str = "test"; number = 10;

Last updated

Was this helpful?