re-write javascript array I am using a long array of over 300 var &amp; 7,000 lines of code written like this:

var a = [];
var b = [];
var c = [];
var d = [];
var e = [];

a[0] = "a";
b[0] = "b";
c[0] = "c";
d[0] = "d";
e[0] = "e";

a[1] = "1";
b[1] = "2";
c[1] = "3";
d[1] = "4";
e[1] = "5";

a[2] = "one";
b[2] = "two";
c[2] = "three";
d[2] = "four";
e[2] = "five";


Im guessing it is the same as a much cleaner and shorter -  

var a = [a,1,one];
var b = [b,2,two];
var c = [c,3,three];
var d = [d,4,four];
var e = [e,5,five];


Is there an easy or automatic way to rewrite the original array like the 2nd method?
First of all I think you meant:

a = ["a","1","one"]; // instead of [a, 1, one]


I handle these rare kind of issues as follow:


Open your browser (the following code is tested against Chrome)
Open the JavaScript console [Control -Shift -J (Chrome:Windows/Linux)]
Copy/paste your own code into the console


and then paste the following code

copy('abcde'.split('').map(function(varName){
return 'var ' + varName + ' = ' + JSON.stringify(window[varName])+';';
}).join('\n'));


If your variable names are more than 1 character use this code instead: (of course the following code won't work with the file example you specified, I changed the variable names for demonstration purpose)

copy(['var1', 'myVar2', 'blablabla'].map(function(varName){
return varName + ' = ' + JSON.stringify(window[varName])+';';
}).join('\n'));



Hit enter


the above code will copy the following JavaScript code into your clipboard:

a = ["a","1","one"];
b = ["b","2","two"];
c = ["c","3","three"];
d = ["d","4","four"];
e = ["e","5","five"];


Paste it into your file, save it and that's all!