Hi!
I'm trying to get into scripting, but can't figure out what I'm doing wrong here. My goal is to populate a C3 Array object using a javascript array.
Here is my script:
//creating a JS array by splitting a string:
const arrayForSplitText = localVars.randomylChosenScrollText.split('.');
//accessing a C3 array object:
const a runtime.objects.ArrayFromConstruct.getFirstPickedInstance();
//This console log works as expected:
console.log(JSON.stringify(arrayForSplitText));
//Function someone here on the forums built for loading a C3 array with a JS array:
function setC3Array(c3ArrayInstance, arr){
try {
const w = arr.length;
let h = arr.sort((a, b) => a.length - b.length)[0].length;
c3ArrayInstance.setSize(w, h);
arr.forEach((x, xi) => {
x.forEach((y, yi) => {
c3ArrayInstance.setAt(y, xi, yi);
})
})
} catch(err){
console.log('Errror on setC3Array function', err);
}
}
//call the function:
setC3Array(a, arrayForSplitText)
//What I get is:
Errror on setC3Array function TypeError: x.forEach is not a function