Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
Reshape Unpivot Columns using Javascript

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!