Removing Those Weird Commas
ES6 template strings join arrays with commas using the toString() method. We can fix that and improve our UI. (5 min. read)
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?