1

I have an array of arrays in coffe script. How to convert it in easy way to string and then back to array? So i m expecting like this.It's easy to do it in ruby using eval.How to achieve that in a coffe script? Thanks in advance.

"[[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

1 Answer 1

8

While you could, in theory, use eval in javascript/coffeescript as well, you probably should not. A better solution would probably be to use JSON, for instance:

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

which outputs:

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

Sign up to request clarification or add additional context in comments.

2 Comments

yeah json is the way to go for this
@alexeyb Then you should mark this as your accepted answer (click the checkmark next to it).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.