2016-07-30 87 views

回答

2

由於Array#map回調有3個參數,第二個參數是index這是造成這種結果。不管你輸入的是function作爲callback,這個參數都作爲該函數的參數傳遞。

parseInt第二個參數是radix因此parseInt('2',1)parseInt('3',2)NaN

執行流程將是:

console.log((['1', '2', '3']).map(function(currenValue, index, array) { 
 
    return parseInt(currenValue, index, array); 
 
}));

我會建議你去與Number

console.log((['1', '2', '3']).map(Number));

相關問題