I have a google sheet with some data in a single column.
How to assign these values to new object like {'value[0]':value[0], 'value[1]':value[1],..., 'value[i]':value[i]}?
I wrote this script, but it assigns pair from last value of names only:
function getIngredientsList() {
const url = "SPREADSHEET_URL";
const ss = SpreadsheetApp.openByUrl(url);
const ws = ss.getSheetByName('Base');
const names = ws.getRange(2, 3, ws.getLastRow() - 1).getValues().map(a => a[0]);
let nameList;
for (let i = 0; i < names.length; i++){
if (names[i] !== ""){
let name = {[names[i]]:names[i]};
nameList = Object.assign(name);
}
}
return nameList;
}
Where I'm wrong and how to fix it?