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.