Trying to make a pivot pivot table but can't figure out why a for loop returns undefiend

I’m trying to make a dynamic pivot table.

I’ve made my groupings and I’m now playing around with how I can get this into a table format.
I’m currently trying to create rows to push into my tables array.
I’m trying to do for loop with with a map method inside, however I can’t figure out why my categories returns [undefined, undefined, undefined]?

const table = base.getTable('report');
let tableArray = [];

let queryResult = await table.selectRecordsAsync();
output.inspect(queryResult);


//Row names
let nameArray = []
for (let record of queryResult.records){
  //nameArray.push(record.name)  
  nameArray.push(record.getCellValue('Select Name')[0].name)  
};
const uniqueNames = [...new Set(nameArray)];
output.inspect(uniqueNames);

//Coloumn names
let itemsArray = []
for (let record of queryResult.records){
  itemsArray.push(record.getCellValue('Working on'))
}
const uniqueItems = [...new Set(itemsArray)]
output.inspect(uniqueItems);

//Make Rows
for(let i=0; i<uniqueNames.length; i++ ){
  
  let categories = uniqueItems.map(record => {`${record}: 'SUM'`});
  output.inspect(categories);
}


//Outcome
output.table([
        {'Name/Item': 'John', Car: '', Bus: '£34', Scooter: '', '':''},
        {'Name/Item': 'Dan', Car: '£32', Scooter: '£70', '':''},
        {'Name/Item': 'Theo', Bus: '£90', Car: '£50', '':''},
    ]);

Output:

  1. {recordIds: Array(7), records: Array(7)}

  2. :arrow_forward:(3) [“Dan”, “John”, “Theo”]

  3. :arrow_forward:(3) [“Car”, “Bus”, “Scooter”]

  4. :arrow_forward:(3) [undefined, undefined, undefined]

  5. :arrow_forward:(3) [undefined, undefined, undefined]

  6. :arrow_forward:(3) [undefined, undefined, undefined]

I figured it out - I was missing a return :face_with_monocle: