Given:
var obj={0:21,1:22}
and
var arr=[21,22]
Why parseInt(obj)returns NaN, but parseInt(arr)returns 21?
parseInt(obj)
NaN
parseInt(arr)
21
I had a function in which I was going to pass int, a hash type objector a simple one array. I expected to parseIntreturn NaNfor objectand array, which will simplify the verification of arguments. What gives?
int
object
array
parseInt
, parseInt . String(obj) "[object Object]" , String([21,23]) "21,23", parseInt , char.
String(obj)
"[object Object]"
String([21,23])
"21,23"
parseInt:
inputString be? ToString (string).
inputString
string
( ).
S , radix-R, Z - S, ; Z - S.
( , , "21,23" → "21").
"21"
Source: https://habr.com/ru/post/1669891/More articles:How to fix a stream error "TouchHistoryMath. Duplicate module provider" - reactjsКак протестировать Angular 2 заголовка, отправленных службой с помощью модуля Http? - unit-testingHow to get std :: thread of the current thread? - c ++How to determine the number of augmented images in Keras? - generatorИтерация через массив строк, извлеченных из MongoDB - mongodbRequest request generated for EntitySet is invalid - entity-frameworkBig gif from a third-party site not showing up on README.md on github? - githubVisual Studio Resharper with TypeScript and node_modules - visual-studioKeras: Binary_crossentropy has negative values - pythonPandas DataFrame How to request the nearest datetime index? - pandasAll Articles