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
js map string trim bug All In One
https://www.cnblogs.com/xgqfrms/p/16015408.html
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14313582.html
未经授权禁止转载,违者必究!