Exclude non-numbers while pushing to an empty array

Hi guys I have this problem where I created a logical statement where numbers should only get pushed to an array. I was wondering if the problem is with my logic (see image attached) Thanks🙌🏼
9 Replies
MarkBoots
MarkBoots3y ago
there are a few issues. you are trying to parse all values to an Int. Also the "3" (3) and "test" (NaN) So now all values are typeof Number. And everything will be pushed to your array [1,25,9,NaN] Short story, you dont need to parseInt
Jochem
Jochem3y ago
typeof "3" is string though, so depending on whether you want those you do need some kind of check... but the input arrays at the bottom don't seem to contain anything that isn't a number, so you really don't need to worry about it
MarkBoots
MarkBoots3y ago
yea, i assumed he doesnt want strings with digits
Jochem
Jochem3y ago
if you want to check if something is a numeric-y value, you can use isNaN
Jochem
Jochem3y ago
not an unfair assumption 🙂
ei
eiOP3y ago
yes that's it will try isNaN, but why NaN not working is kinda sketchy lmao 😅 Thanks for the help guys
MarkBoots
MarkBoots3y ago
np, yw
Jochem
Jochem3y ago
it's weird, but typeof NaN is number
ei
eiOP3y ago
I see. Btw, it is working now THanks
Want results from more Discord servers?
Add your server