[1,2,3].map(parseInt)
来源:互联网 发布:国内erp软件排行 编辑:程序博客网 时间:2024/06/02 01:05
You may consider it [1,2,3].It is wrong. Let us figure it out.
map():
[1,2,3].map(function(a,b,c,d){return a+"-"+b+"-"+c+"-"+d;})//["1-0-1,2,3-undefined", "2-1-1,2,3-undefined", "3-2-1,2,3-undefined"]//first parameter:element which will be use//second parameter:index of the element//third parameter:array itself
parseInt(string,radix):
parseInt("1") //1,the function will use 10 by default without radixparseInt("12a34") //12,only the first number will be returnedparseInt("1",0) //1,if the radix is 0,it will be treated as 10parseInt("1",1) //NaN,if the radix is not 0 and is not between 2 and 36,return NaN
So what we need to do is:
parseInt(“1”,0) //1
parseInt(“2”,1) //NaN
parseInt(“3”,2) //NaN
Then the result is [1,NaN,NaN]
0 0
- [1,2,3].map(parseInt)
- ["1", "2", "3"].map(parseInt)
- 为什么 ["1", "2", "3"].map(parseInt) 返回 [1,NaN,NaN]?
- 为什么 ["1", "2", "3"].map(parseInt) 返回 [1,NaN,NaN]?
- ["1", "2", "3"].map(parseInt) 为何返回[1,NaN,NaN]
- JavaScript:['1','2','3'].map(parseInt)问题解析
- JavaScript:['1','2','3'].map(parseInt)问题解析
- ["1", "2", "3"].map(parseInt) 为何返回[1,NaN,NaN]而不是[1,2,3]
- 解惑 ["1", "2", "3"].map(parseInt) 为何返回[1,NaN,NaN]
- 面试题:为什么 ["1", "2", "3"].map(parseInt) 返回 [1,NaN,NaN]?
- Web前端面试指导(三十六):["1", "2", "3"].map(parseInt) 答案是多少?
- js parseInt和map函数
- parseInt(1 / 0, 19)
- parseInt()
- parseInt()
- parseInt()
- parseInt()
- ParseInt
- CASE WHEN 用法介绍2
- SWFUpload插件探究
- 文章标题
- MyBatis——Dao层开发总结
- Java入门
- [1,2,3].map(parseInt)
- 面向对象——异常
- Linux 终端下颜色的输出
- Swift之as、as!、as?三种类型转换操作符解析
- Kafka学习(一)
- 《Java并发编程实战》读书笔记四:活跃性和性能,死锁和显示锁
- Java语言层面和JVM层面方法特征签名的区别 及 实例分析
- el表达式的转义字符
- redis第二篇:Centos下配置Redis开机启动