zoukankan      html  css  js  c++  java
  • 数组map方法和parseInt方法

     1 <!DOCTYPE html>
     2 <html>
     3     <head>
     4         <meta charset="utf-8">
     5         <title></title>
     6     </head>
     7     <body>
     8         <script>
     9             
    10             //数组map方法,遍历数组
    11             var result= [1,2,3].map(function (item , index){ //参数一;数组元素, 参数二;索引
    12                 return    item+1;
    13             })
    14             console.log(result)
    15             
    16             parseInt(1.8) //1 一个参数,取整
    17             parseInt(101,2)//5  两个参数,将101的二进制转换成十进制 
    18             
    19             // 面试题
    20             var result=[1,2,3].map(parseInt);  //parseInt也是函数
    21             console.log(result)  //[1, NaN, NaN]
    22             
    23             // 转换成
    24             function parseInt(a,b){ //map方法传入了
    25                 //进制转换
    26                 1,0  //0进制  ,如果是0进制,当成是10进制
    27                 2.1  //1进制  NaN
    28                 3,2  //2进制  NaN
    29             }
    30             
    31             
    32         </script>
    33         
    34         
    35     </body>
    36 </html>
  • 相关阅读:
    js交互数据
    js字符串操作
    js数组操作
    hasattr ,setarrt, getattr属性
    装饰器
    redis数据库安装
    ubuntu中mysql数据库安装与删除
    装换器
    jinjia2
    Laravel框架与ThinkPHP框架的不同
  • 原文地址:https://www.cnblogs.com/fsg6/p/13032583.html
Copyright © 2011-2022 走看看