const toNumbers = arr => arr.map(Number);
// Or
const toNumbers = arr => arr.map(x => +x);
// Example
toNumbers(['2', '3', '4']);
// [2, 3, 4]
const toNumbers = arr => arr.map(Number);
// Or
const toNumbers = arr => arr.map(x => +x);
// Example
toNumbers(['2', '3', '4']);
// [2, 3, 4]
For further actions, you may consider blocking this person and/or reporting abuse
Yash Jain -
Sukhrob Tech -
Sebastian Korfmann -
Eran Sakal -
Top comments (2)
You'll get
NaN
in following scenarios:Empty string ->
''
String with space
' '
function definition =>
() => {}
undefined value =>
undefined
null value =>
null
we can use ts or input validation when writing any function