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
Tomas Stveracek -
Harshal Shah -
Imran Shaik -
Daniel Afonso -
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