zoukankan      html  css  js  c++  java
  • ES6 语法记录(迭代)

    本文主要记录在使用Vue开发前端页面时,遇到的前端ES知识点整理.

    1:  ...(三个点) 运算符

      合并数组,   

     合并数组时与ES5的 concat方法一致

    var list=[1,2,23,4]
    undefined
    var a=list[0]
    undefined
    a
    1
    rest=list.slice(1)
    (3) [2, 23, 4]
    [a,...rest]
    (4) [1, 2, 23, 4]

    当合并obj对象时,将对象作为数组0,继续组合...b的数组

    var a={}
    undefined
    b
    (4) [1, 2, 3, 4]
    [a,...b]
    (5) [{…}, 1, 2, 3, 4]
    0: {}
    1: 1
    2: 2
    3: 3
    4: 4
    length: 5
    __proto__: Array(0)

    ...如果用于数组赋值,则必须放到最后

    如以下会报错

    如果将扩展运算符用于数组赋值,只能放在参数的最后一位,否则会报错

    const [...butLast, last] = [1, 2, 3, 4, 5];

    const [first, ...middle, last] = [1, 2, 3, 4, 5];

    用于字符串时,表示将字符串拆分

    [...'helloword']
    (9) ["h", "e", "l", "l", "o", "w", "o", "r", "d"]
    0: "h"
    1: "e"
    2: "l"
    3: "l"
    4: "o"
    5: "w"
    6: "o"
    7: "r"
    8: "d"
    length: 9
    __proto__: Array(0)

    用于Map

    let map=new Map([[1,'one','two']]);
    undefined
    map
    Map(1) {1 => "one"}
    map[0]
    undefined
    map.1
    VM1641:1 Uncaught SyntaxError: Unexpected number
    map
    Map(1) {1 => "one"}[[Entries]]0: {1 => "one"}size: (...)__proto__: Map
    map.keys()
    MapIterator {1}[[Entries]]0: 1__proto__: Map Iterator[[IteratorHasMore]]: true[[IteratorIndex]]: 0[[IteratorKind]]: "keys"
    [...nap.keys()]
    VM1757:1 Uncaught ReferenceError: nap is not defined
        at <anonymous>:1:1
    (anonymous) @ VM1757:1
    [...map.keys()]
    [1]
  • 相关阅读:
    显示等待WebDriverWait+EC
    mac 上查看python3的各种安装路径
    layui弹窗全屏显示
    Mysql 一些细节方面解析(一)--MyISAM和InnoDB的主要区别和应用场景
    命令关闭tomcat
    xml 写sql语句文件头
    mysql update 修改多个字段and的语法问题
    zookeeper安装
    Java 基础--移位运算符
    SQL mybatis动态查询小结
  • 原文地址:https://www.cnblogs.com/mailaidedt/p/12643078.html
Copyright © 2011-2022 走看看