Hi I'm getting an issue where the Addition assignment += is returning a null value and I'm not sure why this is. Here is an example of this circled in green:
Here is the code I'm working with:
for (let i = 0; i < res.rowCount; i++) {
let username = res.rows[i].user_id
let level = res.rows[i].lvl
let xp = res.rows[i].xp
embed.description += `# ${i+1}. **${username}** **Level: ${level}** | **XP: ${xp}**\n`;}
message.reply({ embeds: [embed]});
}
It sounds like embed.description has a null initial value, and concatenating to that will first "stringify" that value. Observe:
var foo = null;
foo += "test";
console.log(foo);
You can conditionally set embed.description before updating it, so if it's null make it an empty string:
embed.description = embed.description ?? '';
For example:
var foo = null;
foo = foo ?? '';
foo += "test";
console.log(foo);
It looks at the first loop iteration, embed.description is null, you concatenated null with a string which gives "null<string>".
var a = null;
a += "string";
console.log(a);
try setting blank/empty string to embed.description before for loop, like
embed.description = "";