I got this to work using Chrome on Windows (with some unnecessary steps.)
A csv has these contents:
"1" "b" "c" "d"
"2" "f" "g" "h"
Open the file with a text editor and paste the contents into a script, then surround the string with backticks:
const csv = `1,b,c,d
2,f,g,h`;
Here's the full script:
<html>
<script>
const csv = `1,b,c,d
2,f,g,h`;
// Replaces newline characters with commas
const csvModified = csv.replace(/\n/g, ",");
// Converts the string to an array
const arr = csvModified.split(",");
//Separates the keys and values into their own arrays (assuming every 4th item is a key)
let keys = [], vals = [];
for(i = 0; i < arr.length; i++){
if(i % 4 == 0){ keys.push(arr[i]); }
else { vals.push(arr[i]); }
}
// Makes a javascript object (i.e. a dictionary) from the two arrays
const dict = {};
for(i = 0; i < keys.length; i++){
localVals = vals.splice(0,3); // Extracts the first three items as a new array
dict[keys[i]] = localVals; // Adds a property (named for the key) to the object
}
// Prints the object to the browser console
console.log(dict);
</script>
</html>
The object looks like:
{
1: ["b", "c", "d"]
2: ["f", "g", "h"]
}