I have a requirement where I need to reshape data in a csv. Below is the csv
Set No ;Res No ;A ;B ;C
1451 ;1123 ;0 ;1 ;2000
1351 ;1133 ;0 ;2 ;3000
And here is the desired output.
Set No ;Res No ;Attrib ;Value
1451 ;1123 ;A ;0
1451 ;1123 ;B ;1
1451 ;1123 ;C ;2000
1351 ;1133 ;A ;0
1351 ;1133 ;B ;2
1351 ;1133 ;C ;3000
I tried the below code but it is running an infinite loop
var text = a
var linearray = String(text).split("\r\n")
var len = linearray.length
for (var i=0; i<linearray.length-1;i++)
{
var temparray = linearray[i].split(";")
for(j = 0;j<temparray.length-1;j++)
{
temparray.push([]);
}
linearray[i] = temparray.join(";")
}
linearray.join("\r\n")
"a" in the code contains the value of the csv file. Can you please suggest what I am doing wrong and what code should I write to get the desired result.