Removing Those Weird Commas
Discover how to address the issue of unwanted commas in your JavaScript template literals when embedding array results. This lesson teaches you how to properly format strings by joining arrays without commas, improving your functional Wikipedia search UI using RamdaJS tools.
We'll cover the following...
If you stayed sharp last lesson, you noticed something off about our fresh UI.
It has extra commas! Why??
Template Literals
It’s all about how template literals join things. If you stick in an array, it’ll join it using the toString() method.
See how this becomes joined?
Template literals do that if you put arrays inside of them.
So by mapping our Wikipedia results inside of a template literal, we accidentally had commas inserted in between them!
You can fix that by joining the array without commas. Just use an empty string!
Here’s with our [1, 2, 3] example
No more commas! Let’s try that with our results map.
Check out your UI. Looks much nicer right?