I have the following array
var a = ["Banana/hgd/kjjkds", "Orange/kldj/kdl",
"Apple/jlds/ldks", "Mango/dsfj/dskj"]
Now I want to re-create it as below and make the output
{
"a1" : "Banana",
"a2" : "hgd",
"a3" : "kjjkds"
}
{
"a1" : "Orange",
"a2" : "kldj",
"a3" : "kdl"
}
{
"a1" : "Apple",
"a2" : "jlds",
"a3" : "ldks"
}
{
"a1" : "Mango",
"a2" : "dsfj",
"a3" : "dskj"
}
I tried the following method but without any success:
var b = [];
for (var i = 0; i< a.length; i++) {
b['a1'] = a[i].split("/")[0];
b['a2'] = a[i].split("/")[1];
b['a3'] = a[i].split("/")[2];
console.log(b);
b.push(b);
}
The console prints all the array created but the array b only shows the last one. How can i get it to work? Please help.
b.push(b);in your code, then you should already know that something is not right. You are adding the array to itself...