I would like to create a miltidimentional array as follows so
var multi-arr = [
["A,2,5"],
["B,4,4"],
["C,4,4"]
]
from string values gotten from the database using ajax.
string data gotten from db delimited by #
var string = "A,2,5# B,4,4# C,4,4";
I split the string by a '#' delimiter
arr1=string.split(/\s*\#\s*/g);
creating the array below
var arr = ["A,2,5", "B,4,4", "C,4,4"];
I want to further split the items in the above array using the comma ',' as a delimiter and create a multidimensional array
My problem is the loop only pushes in the last item in the array
for (i = 0; i < arr.length; i++) {
var arr2 = [];
arr2[i]=arr2.push(arr1[i].split(/\s*\,\s*/g));
}
console.log(arr2);
What am i doing wrong? or what can i do better?