I'm relatively new to JavaScript and I want to understand the logic behind this snippet of code I found on this site: [...num+''].map(n=>+n) //[1, 2, 3, 4, 5]
I would've asked in a comment on the original answer, but I don't have enough rep... yet.
I was working on a coding challenge on Codewars and this answer from another question on this site worked really well, and was really concise, but I'm relatively new to JavaScript, and would like some clarification on why this worked.
The original post basically said that this function returns a digits in a number as an array of strings:
let num = 12345;
[...num+''] //["1", "2", "3", "4", "5"]
and that this little addition converted the strings back to integers:
[...num+''].map(n=>+n) //[1, 2, 3, 4, 5]
I would just google this on my own, but I don't know what any of these syntaxes are actually called...