https://stackoverflow.com/questions/71398027/supab...
# javascript
g
Supabase returns an array of rows of objects. The objects include the column names and data. It works first time because you get back an empty array [] after that you need to get the array with something like data[0].arraycol
p
So how can I change my code to do this @User?
||Fun fact: It's a discord.js bot written in node||
g
I'm a bit perplexed by your code. splice does not seemed formatted correctly but probably never runs with your if on the supabase table array. Not sure why you would want it anyway. First just return {data} = your select Then
Copy code
let memberArray = []
if (data.length) memberArray = data[0].member_join 
if (!memberArray.includes(roleId)) memberArray.push(roleId)
If I got that correct it should insert a new role if there was no guild_id match (new record), the array is empty or the role does not exist in the array. You could probably also optimize to not do the upsert if your rollId already exists if appropriate.
p
Thanks. I actually do want to upsert it even if it's there because then I remove. Similar to a toggle.
Yeah I change the splice code too now.
You answered my main problem thank you!