Q:

Jquery reading array in textarea

I need to be able to paste something like this inside a textarea:
var cars = new Array(new Array(3), new Array(3));
cars[0][0] = 'FORD';
cars[0][1] = 'Focus';
cars[0][2] = 'Mondeo';
cars[1][0] = 'VOLKSWAGEN';
cars[1][1] = 'Golf';
cars[1][2] = 'Polo';
cars[1][3] = 'Lupo';

An afterwards being able to access cars array from my script as a common variable.
Been trying with eval, but after googling I'm really scare of it.
Can somebody help me?

A:

You can attach arbitrary data to any html element with jquery .data() method.
So given a textarea like this:
<textarea id="txa"></textarea>

From jquery you could do:
var cars = new Array(new Array(3), new Array(3));
cars[0][0] = 'FORD';
...
$('#txa').data('myvar', cars);

And then retrieve it later with:
var arr = $('#txa').data('myvar');
alert( arr[0][0] ); //alerts FORD

UPDATE:
Now, based on your last comments, it seems what you just need is the eval() function to execute the javascript code you have in your textarea, like this:
code = $('textarea').val();
eval( code );
alert( arr[0][0] ); //alerts FORD

See working demo

