While map over an object remove the , ?

Looping over an object and it keep adding the , to the dom. I know with an array you can use .replace(). I cant find anything similar for objects.
5 Replies
13eck
13eck3y ago
Can you please share the code you're using? Without code no one can begin to guess what's happening
Errtu
ErrtuOP3y ago
It is a lot of code, the issue is in the dayView generate mark up method https://github.com/bsupinski/weather_app
GitHub
GitHub - bsupinski/weather_app
Contribute to bsupinski/weather_app development by creating an account on GitHub.
13eck
13eck3y ago
Oh, I see what's happening here! Array.map() returns a new array, but when you're injecting it into the DOM you're using Element.insertAdjacentHTML() which requires a string. So JS is stringifying it, which by default an array is stringified as a comma-separated list. What you want to do in dayView.js is
return this._data.fiveDay.map().join(' ')
return this._data.fiveDay.map().join(' ')
This will create a string of the array items with a space as a separator instead of a comma.
Errtu
ErrtuOP3y ago
Man i am an idiot, I tried that, and couldnt figure out why it didnt work. But I was putting it before the map closing ).
Thank you @13eck
13eck
13eck3y ago
👍
Want results from more Discord servers?
Add your server