I am doing tests on google-sheets and I have this script: What it does is consult data and insert it into the sheet but it does not do so in the desired order.
what I have: bad sheet
what I want: good sheet
function callapi() {
var response = UrlFetchApp.fetch("https://jsonplaceholder.typicode.com/todos");
var json = response.getContentText();
var data = JSON.parse(json);
for ( var i = 0; i < data.length; i++) {
var title = data[i].title
var id = data[i].id
var userId = data[i].userId
Logger.log(title)
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(sheet.getLastRow() + 1,1).setValue([title]);
sheet.getRange(sheet.getLastRow() + 1,2).setValue([id]);
sheet.getRange(sheet.getLastRow() + 1,3).setValue([userId]);
}
}
I appreciate any help.