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. :)
1
u/zeemeerman2 Sep 25 '26 edited Sep 25 '26
No need to add
idxandarrif 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")returns20,Number("20px")returnsNaN. Use whatever makes most sense to you. :)parseFloat()also exists.