Skip to content
Advertisement

Converting values from for loop to json format

Below is a snippet of a for loop where I sort txt file names. I am then trying to save the results in a json format file. However it results in an invalid json format due to the last , inserted in obj. How could i convert to json format the values from the for loop?

script

JavaScript

Desired output

JavaScript

Current output

JavaScript

Advertisement

Answer

Observe that each line except the first begins with “,n”.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement