1

i get this string from a function that reads my .csv file and now i want to convert it to an js array of objects (without the header)...

can anyone help me?

"Name"  "Address"   "Central"   "Unfiltered"    "Description"   "DatapointType" "Security"
"Placeholder1"  "0/0/-" ""  ""  ""  ""  "Auto"
"Placeholder2"  "0/-/-" ""  ""  ""  ""  "Auto"
"Placeholder3"  "0/0/1" ""  ""  ""  "DPT-1" "Auto"
"Placeholder4"  "0/0/2" ""  ""  ""  "DPT-3" "Auto"

i already tried some solutions from here but i think they all dont work cause my csv isnt seperated by "," or ";" (for example)

my csv is seperated by tabs

thanks for your time :)

  • So what _is_ it separated by then, are those supposed to be tabs, or what? – CBroe Aug 11 '22 at 05:55
  • What *is* the separator? I see two spaces, sometimes 3 or 4... any rule? – trincot Aug 11 '22 at 05:56
  • its seperated by tabs sry – David Küng Aug 11 '22 at 06:03
  • 1
    this is an opinion: don't re-invent the wheel, there are a few great libraries that handle CSV's - of course, it would help if you had a CSV in the first place – Jaromanda X Aug 11 '22 at 06:09
  • The Tab character is most-easily represented like so: `"\t"`. Split each row on that string. Use a loop inside a loop. Cross-reference with the header row to figure out what name to give each property. – Tom Aug 11 '22 at 06:15
  • 1
    To second @JaromandaX's point: there _are_ great libraries out there. The TSV format permits tabs within a field's quotes, and there are probably other rules about special characters. Writing a proper parser is non-trivial. Unless your data is very clean or very simple, it will take less time to find and install a good library than to identify and fix all the problem cases. – Tom Aug 11 '22 at 06:17

0 Answers0