I'm new to javascript and a novice coder. I have been trying to write a simple script for a Google Sheet to concatenate two columns of data into another column:
My script below runs fine but only produces Aaron Ward as line 1 of Desired Column C. I'm sure it is really simple what I am missing, but if anyone has a minute to help a rookie, I'd really appreciate it.
function concatenate() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
var lr = sheet.getLastRow()
var values1 = sheet.getSheetValues(1, 1, lr, 1);
var values2 = sheet.getSheetValues(1, 2, lr, 1);
var results = [];
for (var i = 0; i < lr; i++) {
results = [values1[i] + " " + values2[i]];
Logger.log(results);
sheet.getRange(1, 3, results.length).setValues([results]);
}
}
Array#mapand/orArray#jointo simplify your code / increase its expressiveness. Feel free to also submit your fixed code as an answer if you feel it will be useful to others, or delete the question if you think it will not - tehhowch