into an array that can be used in p5 via createFileInput. Currently, I have split the array into the respective rows using the code below via double commas, but I’m not sure how to add the rows to a new multidimensional array as numbers instead of as a string.
function loadFile(file){
array = file.data;
splitStrings = split(array,', ,');
}
The function uses method String::replace() together w/ the regex/[\[\]]/g in order to remove each [ & ] leftover characters from each string before we split() it:
In addition to that it iterates the outer array via method Array::forEach():
And then each inner array is transformed into a 2d array via Array::map()'s callback:
And finally inside that callback we have Float64Array which converts the newly split() string array into a typed array of float values:
Here’s the full code which can be copied & pasted into the browser’s console b/c it’s just vanilla JS:
( just add a surrounding pair of brackets) You just have to read it with parse, and that’s all.
let big = JSON.parse(s)
// access
console.log(big). // array(4) most external
console.log(big[0]) // array(4) a line
console.log(big[0][0]) // array(3) one vector
console.log(big[0][0][0]) // an element -7.5.