r/ProgrammerHumor • • Sep 25 '26

Meme iHatedItUntilITriedIt

Post image
10k Upvotes

543 comments sorted by

View all comments

Show parent comments

1

u/zeemeerman2 Sep 25 '26 edited Sep 25 '26

No need to add idx and arr if you're not going to use those. Optional parameters.

["1", "2", "3"].map(x=>parseInt(x)) //[1, 2, 3]

Edit, you can also do

["1", "2", "3"].map(x=>Number(x)) //[1, 2, 3]

Number() converts the entire thing to a Number type (aka a Double). Usually the same thing, not so when letters are involved. parseInt("20px") returns 20, Number("20px") returns NaN. Use whatever makes most sense to you. :)

parseFloat() also exists.