Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

100
Vistas
Trim method not working for Array when reading from String

I have researched plenty of .trim method questions to see if someone had my same issue but I haven't come across it and I think it's because of something I did wrong and I just can't see it.

I want to extract the .CSV line and trim it, so I went ahead and did this:

const convertCSVLine = (csvline) => {
  const cell = csvline.trim().split(',');
  const id = cell[0];
  //get rid of spaces..
  const customer = cell[1];
  const product = cell[2].trim();
  const price = cell[3].trim();

  return new SalesOrder(id, customer, product, price);
};

const test = '101,Charlie Anderson, Bike, 10.00';

console.log('SALES ORDER:', convertCSVLine(test));

But for some reason I get this error in my browser when I trim those two lines:

Uncaught TypeError: Cannot read properties of undefined (reading 'trim')

Like .trim() works on the first cell line (because its going to be reading a whole .CSV string altogether so I need to separate the lines) but then I want to trim the product and price part of the new array by themselves but now its throwing this error.

I'm relatively new to coding and have had a semester of Java so I know the pain, I'm just an intermediate programmer.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda