There were 2 things wrong:
1. I needed (foreignKeys.length > 0) && instead of foreignKeys &&
2. I needed Object.values(foreignKeys[0]).map instead of foreignKeys[0].values.map
[Note: using foreignKeys[0].values.map was a suggestion from CoPilot and it looked strange to me at the time it was suggested, but I thought to myself, "well, it's coming from an AI so it must be correct." Lesson learned!!