0

im new to js, have two question about how to parse a csv, i have a simple csv with two column, column1:'user', column2:'amount'

  1. how can i get one array with all the 'user' column value and one array with all the 'amount' column value?

  2. And can i loop trough the rows and use index to get the value of the two column? something like csv['amount'][0] or csv[0][1] or something like this?

ty.

2
  • Would you show a sample csv file here? Commented Jul 26, 2021 at 3:02
  • what do you mean ? it's a csv with 2 column as i said column1 with users so strings with usernames and second columns with amount, with int prices. Commented Jul 26, 2021 at 9:55

1 Answer 1

1

First, declare 2 arrays, one for user, one for amount.

And then read this post to know how to read a file line by line.

After that, read this post to know how to split a string with a comma separator.

Finally, use the array.push() method to push the data into an array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.