Search code examples
haxe

Way to print for eval (literals) instead of for human-readable?


I see that trace() and Sys.print() both give me human-readable output. For example, if I print out the array

var a = ["", "1", "", "2", "3"];

I get printed:

[,1,,2,3]

Is there some kind of "eval print" function that will give me output instead like:

["", "1", "", "2", "3"]

That is, the literal that I could then use to copy/paste into code if I wanted to (and, incidentally, what could be eval'd to give me that exact array of strings).


Solution

  • You could use Json for that

    trace(haxe.Json.stringify(a));