Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!