0

I'm trying to have an api return a few arrays, and have my code append each array item to a new Discord embed. So far my code is:

cleanedSearchArray.forEach( lyricResult => lyricSearchEmbed.addField('\u200B' + lyricResult, 'by ' + cleanedSearchArtistArray.forEach()));

I'm trying to have my embed output:

song0
by artist0
song1
by artist1
song2
by artist2

but instead, I get:

song0
by function forEach() { [native code] }
song1
by function forEach() { [native code] }
song2
by function forEach() { [native code] }

Any way to get the desired output?

BTW cleanedSearchArray includes [song0, song1, song2] and cleanedSearchArtistArray includes [artist0, artist1, artist2]

Azeem
  • 11,148
  • 4
  • 27
  • 40
MaddieX
  • 22
  • 3

1 Answers1

0

You're getting that output because you're not doing anything with your second forEach() loop cleanedSearchArtistArray.forEach().

But regardless, you could achieve what you want by using join()

cleanedSearchArray.forEach( lyricResult => lyricSearchEmbed.addField('\u200B' + lyricResult, 'by ' + cleanedSearchArtistArray.join(', '))); // This will result in: song1 by artist1, artist2
Syntle
  • 5,168
  • 3
  • 13
  • 34