将Array转换为字符串并返回到coffee脚本中的数组

ale*_*eyb 1 coffeescript

我在coffe脚本中有一个数组数组.如何以简单的方式将其转换为字符串然后返回到数组?所以我期待这样.使用eval在ruby中很容易做到.如何在coffe脚本中实现这一点?提前致谢.

"[[2,3,4],[2,3,4],[4,6,7]]" =>string
and then [[2,3,4],[2,3,4],[4,6,7]] back to an array again
Run Code Online (Sandbox Code Playgroud)

Mar*_*ahl 8

虽然理论上你也可以在javascript/coffeescript中使用eval,但你可能不应该这样做.一个更好的解决方案可能是使用JSON,例如:

coffee -e 'console.log JSON.parse(JSON.stringify([[1,2,3],[4,5,6]]));'

哪个输出:

[ [ 1, 2, 3 ], [ 4, 5, 6 ] ]