Hello,
I'm starting to use Excel Office Script on Excel Online and I have a problem with the creation of an array to make a unique setValues. My function is inside an async function.
1°) I call a jotForm API and gets an object in return
2°) I need to iterate through the object and gets some multiple answers
My problem is in the iteration : I'm getting in return an array like this
["Question1-element1","Question1-element2,"Question1-element3","Question2-element1","Question2-element2","Question1-element3"]
But because of setValues and how to write answers to each rows, I need to return an array like this :
[["Question1-element1","Question1-element2,"Question1-element3"],["Question2-element1","Question2-element2","Question1-element3"]]
There each questions are divided and will be written on a different row.
Here is my code :
let fetchResult = await fetch(**fecthURL**);
let json: string = await fetchResult.json();
const result: Object[] = json['content'];
let rows: (string | boolean | number)[][] = [];
let subRows: (string | boolean | number)[][] = [];
let newArray: (string | boolean | number)[][] = [];
let counter:number = 0;
for (const [key, value] of Object.entries(result)) {
rows.push([value["id"], value["created_at"]]);
for (const [subKey, subValue] of Object.entries(value["answers"])) {
if (arrayControl.indexOf(subValue["type"]) === -1) { // I have an array to filter some informations
if (subValue.hasOwnProperty("answer")) {
subRows.push(subValue["answer"]);
}
else {
subRows.push("");
}
}
}
}
What I get from that is all the answers in one line.
But I can't seem to figure out how to push each answer in an array structure like : [[],[],[];[]]. Instead, I get the array structure [,,,,]. I need it because of the setValues in the end :
workSheet.getRangeByIndexes(1,1,subRows.length,subRows[0].length).subRows(newArray)
Any chance someone could have an easy fix for that ?
Thank you in advance,
Cedric
Bookmarks