zoukankan      html  css  js  c++  java
  • 解构赋值、

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
        
    </body>
    <script>
        // 新增赋值方式:解构赋值
        // 解构:解开,结构
    
        // 数组的解构:按照顺序一一对应,没有对应,为undefined
         var arr = ["hello",3.1415,true];
         var [c,b,a,d,e,f] = arr;
         console.log(a);//true
         console.log(b);//undefined
         console.log(c);//hello
         console.log(d);//u
         console.log(e);//u
         console.log(f);//u
    
    //     字符的解构:按照顺序一一对应,没有对应,为undefined
         var str = "hi";
         var [a,b,c,d] = str;
         console.log(a)//h
         console.log(b)//i
         console.log(c)//u
         console.log(d)//u
    
        // 对象的解构:按照key一一对应,没有对应,为undefined
         var obj = {
             name:"admin",
             age:18,
             sex:1
         }
         var {sex,age,name,like} = obj;
         console.log(name)//admin
         console.log(age)//18
         console.log(sex)//1
         console.log(like)//undefined
    
    
        // 参数的解构
         function fn({name,age}){
             // name
             // age
         }
         fn({name:"admin",age:19})
    
         function fn(){
             return ["hello","world"]
         }
         var [a,b] = fn();
    
         var a = 10;
         var b = 20;
         var [b,a] = [a,b];
         console.log(a,b)//20 10
    </script>
    </html>
  • 相关阅读:
    Axure学习二:基础教程
    Axure 学习一:基础知识详解参考文档
    iOS 加载动态库报错问题
    iOS 9 之 Spotlight框架
    iOS 之 新功能、扩展
    mysql慢查询
    php curl多线程抓取网页
    php读取qqwry.dat ip地址定位文件的类
    php比较加赋值语句
    yaf在windows7下32位的安装教程
  • 原文地址:https://www.cnblogs.com/hy96/p/11435830.html
Copyright © 2011-2022 走看看