美文网首页
展开语法(Spread syntax)

展开语法(Spread syntax)

作者: SingleDiego | 来源:发表于2019-03-05 15:15 被阅读0次

参考文档:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Spread_syntax

合并数组:

const first = [1, 2, 3];
const second = [4, 5, 6];

[...first, ...second]; // [1, 2, 3, 4, 5, 6]

合并数组的同时插入元素:

['a', ...first, ...second]; // ["a", 1, 2, 3, 4, 5, 6]

['a', ...first, 'b', ...second, 'c']; // ["a", 1, 2, 3, "b", 4, 5, 6, "c"]

复制数组:

[...first]; // [1, 2, 3]

合并对象:

const first = {name: 'tom'};
const second = {age: 18};

{...first, ...second}; // {name: "tom", age: 18}

合并对象并插入新属性:

{...first, ...second, location: 'china'}; // {name: "tom", age: 18, location: "china"}

复制对象:

{...first}; // {name: "tom"}

相关文章

  • ES6

    const {} Is the same as Spread syntax 展开语法(Spread syntax)...

  • 展开语法(Spread syntax)

    参考文档:https://developer.mozilla.org/zh-CN/docs/Web/JavaScr...

  • js中的展开语法/剩余语法

    展开语法(Spread syntax) 可以在函数调用/数组构造时, 将数组表达式或者string在语法层面展开 ...

  • 【ES6基础】展开语法(Spread syntax)

    展开语法用"..."进行表示,展开语法将可迭代的对象拆分成单个的值(语法层面展开)。 展开语法通常用于将可迭代的对...

  • JS - 扩展运算符和rest参数

    spread syntax 可以将 iterator 对象(如 array、string 等) 展开,在需要参数(...

  • js spread syntax

    前段为这个解析api的dom元素生成的小工具[https://github.com/walkerwzy/code_...

  • babel小记

    对于不支持对象的解构展开语法,可以安装babel插件transform-object-rest-spread。

  • VIM编辑器

    一:语法高亮 syntax on(设置语法高亮) syntax off(关闭语法高亮) 二:显示行号 set ...

  • AST反混淆实战(一)

    AST简介 抽象语法树(Abstract Syntax Tree,AST),或简称语法树(Syntax tree)...

  • Vue Antd Admin中展开运算符(spread oper

    Vue Antd Admin中,有很多地方用到了ES6的新语法:展开运算符(spread operator)。我这...

网友评论

      本文标题:展开语法(Spread syntax)

      本文链接:https://www.haomeiwen.com/subject/kxdnuqtx.html