js Array.map(Number) All In One


js Array.map(Number) All In One

map() 方法創建一個新數組,其結果是該數組中的每個元素是調用一次提供的函數后的返回值。

let newArray = arr.map(callback(currentValue[, index[, array]]) {
  // return element for newArray, after executing something
}[, thisArg]);

arr.map(Constructor)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

demo

["1", "2", "3"].map(parseInt);
// (3) [1, NaN, NaN]

["1", "2", "3"].map(Number);
// (3) [1, 2, 3]

parseInt

Number.parseInt(string,[ radix])

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt

parseInt(string [, radix])

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

構造函數, 立即執行

new Number(value)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/Number

Number(value)

refs



©xgqfrms 2012-2020

www.cnblogs.com 發布文章使用:只允許注冊用戶才可以訪問!

原創文章,版權所有©️xgqfrms, 禁止轉載 🈲️,侵權必究⚠️!



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM