Parses a value into a finite integer, returning undefined if parsing fails.
undefined
Floats are truncated toward zero. Trailing non-numeric characters (e.g. '42abc') cause it to return undefined. Whitespace is trimmed.
'42abc'
toInt('42') // 42toInt(' -7 ') // -7toInt('1.9') // 1toInt('42abc') // undefinedtoInt('abc') // undefinedtoInt('') // undefinedtoInt(3.7) // 3 Copy
toInt('42') // 42toInt(' -7 ') // -7toInt('1.9') // 1toInt('42abc') // undefinedtoInt('abc') // undefinedtoInt('') // undefinedtoInt(3.7) // 3
Parses a value into a finite integer, returning
undefinedif parsing fails.Floats are truncated toward zero. Trailing non-numeric characters (e.g.
'42abc') cause it to returnundefined. Whitespace is trimmed.