Key Takeaways
["10","10","10"].map(parseInt) yields 10, NaN and 2 because the second arguments are 0, 1 and 2. For these agreed decimal integer strings, use map(text => parseInt(text, 10)). That fixes argument adaptation, but parseInt("10px", 10) still returns 10.
- map supplies value, index and array; parseInt uses the second position for the radix.Read the supporting section: Expand the actual calls
- Three identical strings produce 10, NaN, 2 with the direct callback, versus 10, 10, 10 with an explicit decimal adapter.Read the supporting section: Hold the text constant
- Fix callback adaptation separately from input validation; an explicit radix still permits prefix parsing.Read the supporting section: An adapter is not a complete data policy
In this article
Expand the actual calls
MDN’s map reference describes three callback arguments. Passing parseInt directly places the array index in its radix position; it is not equivalent to repeatedly calling parseInt(text) alone. The third argument does not repair the mismatch.
At index 0, radix 0 invokes the parser’s default interpretation. At index 1, the radix is invalid and the result is NaN. At index 2, binary 10 equals decimal 2. The second string need not contain any corrupt data for the result to fail.
Hold the text constant
Both drafts are authored examples, not captured AI replies. The three-item case was executed in Node.js 22.23.2 on December 1, 2026. Results were recorded with String per element: JSON serialization would otherwise turn NaN into null and obscure the diagnostic value. The input array remained unchanged.
const cells = ["10", "10", "10"];
const wrong = cells.map(parseInt);
console.log(wrong.map(String)); // ["10", "NaN", "2"]
const decimal = cells.map(text => parseInt(text, 10));
console.log(decimal); // [10, 10, 10]
console.log(parseInt("10px", 10)); // 10| Index | Text | Equivalent incorrect call | Result |
|---|---|---|---|
| 0 | 10 | parseInt("10", 0) | 10 |
| 1 | 10 | parseInt("10", 1) | NaN |
| 2 | 10 | parseInt("10", 2) | 2 |
An adapter is not a complete data policy
The parseInt reference describes integer-prefix parsing. Radix 10 fits the agreed decimal strings here, but does not reject the entire string 10px or preserve the fractional part of 10.5. Decimal quantities, strict whole-string validation and exact long identifiers require their own contracts.
Specify signs, fractions, whitespace, units and missing values before deciding to reject, preserve or convert them. The radix and identifier guide explains why leading zeros may belong to an identifier. Do not strip meaningful characters simply to obtain a numeric array.
Review both sides of a callback boundary
Place the supplying API’s argument order beside the called function’s signature and expected results. Then add nondecimal values, empty strings, 10px and fractions. This small adapter is not a universal number-cleaning function.
The numeric-sorting input contract addresses comparators and mutation. This article addresses callback adaptation; sorting, aggregation and delivery still need separate verification after parsing.


