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
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 parseInttypeof "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 ityea, i assumed he doesnt want strings with digits
if you want to check if something is a numeric-y value, you can use
isNaN
not an unfair assumption 🙂
yes that's it
will try isNaN, but why NaN not working is kinda sketchy lmao 😅
Thanks for the help guys
np, yw
it's weird, but
typeof NaN
is number
I see. Btw, it is working now
THanks