I have a comma-separated string that I want to convert into an array, so I can loop through it.
Is there anything built-in to do this?
For example, I have this
As @oportocala mentions, an empty string will not result in the expected empty array.
So to counter, do:
str
.split(',')
.map(entry => entry.trim())
.filter(entry => entry)
For an array of expected integers, do:
str
.split(',')
.map(entry => parseInt(entry))
.filter(entry => typeof entry ==='number')