ToScript()
Creates a JavaScript expression that assigns the value of a variable to a JavaScript variable. This function can convert strings, numbers, arrays, structures, and queries to JavaScript syntax that defines equivalent variables and values.
ToScript( cfvar=any, javascriptVar=string, outputFormat=boolean, ASFormat=boolean );
Returns: String
Examples
// Struct
Struct = {};
Struct[1] = "lucee";
jsVar = serializeJson(Struct);
resStruct = ToScript(struct, "jsVar");
writeDump(resStruct);
// Array
Array = [];
Array[1] = "lucee";
jsVar = serializeJson(Array);
resArr = ToScript(Array, "jsVar");
writeDump(resArr);
// Query
Query = queryNew( "name,age", "varchar,numeric", {name = "Susi", age = 20 } );
resQry = ToScript(Query, "Query");
writeDump(resQry);
// String
Str = "test";
resStr = ToScript(Str, "Str");
writeDump(resStr);
// Number
number = 10;
resNum = ToScript(number, "number");
writeDump(resNum);
See also
- Strings
- JavaScript
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)