Skip to content
Advertisement

Trying to copy data from a file to an array but it gives me error

Hi I am new on programing and I am having a problem I am trying to copy some things from a file to a array and I just want to copy in the position 1,2,3 and 4 from the file. Example copy to the array 11 , G , 0 , 20.

FILE TEXT:
0;11;G;0;200;1
2;10;F;0;300;2
0;12;J;0;100;3

JavaScript

ERROR:

JavaScript

Advertisement

Answer

If only 4 values are needed from the input array are needed, why not just read these specific values?

JavaScript

If it is needed to read the columns with indexes [1..4] from the file containing 6 columns per line, it is cleaner to read the source file line by line, split each line by ;, skip 1 column with index 0, and keep the 4 columns.

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