Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
How can you use the single elements of the row / columns from the CSV file to Javascript and use them as a variable to use in the code?

Title says the question but to be more specific and using an example given:

  • | Name | Surname | Age |
  • | Robert | Red | 25

and I want to use the name Robert in the code like a variable but to export it from the CSV file. (so something like csv.name[1]) I've been studying for 2/3 months now so I'm totally a beginner. I've been searching online or in forums but couldn't find anything. Let me know if there's something confusing. Have a wonderful day all.

Edit* and then you can do like

  • var name = csv.name[1]
  • console.log(name)

And by editing the name automatically will change the output.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Since this post is tagged with node.js, I'm going to assume that you are actually using it.

Javascript doesn't have any built-in ways to directly access rows and columns from a csv file. You have to firstly parse the csv file into a type which Javascript can understand.

That being said, your best bet might be installing the following npm package (or just the csv-parse subpackage).

If you don't want to install additional npm packages, take a look at this answer. It's a simple Javascript function that allows you to parse a csv file into an array which you can access like you mentioned in your question (array[row][column]).

about 4 years ago · Juan Pablo Isaza Relatório

0

You might look at d3-dsv (delimiter seperated values) part of the d3 library.

const csvInput = "Name,Surname,Age\nRobert,Red,25\nJudith,Gray,29"

const parsed = d3.csvParse(csvInput);

console.log(parsed[0].Name);

console.log(parsed);
<script src="https://cdn.jsdelivr.net/npm/d3-dsv@3"></script>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda