展开符和解构赋值

一、展开符

展开符(剩余操作符):...
1.展开符号

'use strict';
let arr_one = [1,3];
let arr_two = [4,5,...arr_one];
console.log(arr_one);//[ 1, 3 ]
console.log(...arr_one);//1 3
console.log(arr_two);//[ 4, 5, 1, 3 ]

2.剩余操作符(类似arguments)

'use strict';

function test(ss,...others){
    console.log(arguments);//{ '0': 1, '1': 2, '2': 3, '3': 4 }
    console.log(ss);//1
    console.log(others);//[ 2, 3, 4 ]
};
test(1,2,3,4);

一、解构赋值

解构赋值有种形式;

  1. 解构数组
'use strict';

function test(){
    return [1,2,3];
};
let [one,two,three] = test();
console.log(one,two,three);//1 2 3

2.解构对象
解构对象中定义的变量和常见的对象有所区别,在定义变量的时候,键值对中“键”对应的是要解构对象的属性,而“值”才是新定义的变量,如下面案例中的变量“one_test”才是新定义的变量,前面的“one”是test()返回对象的“one”属性;

'use strict';
function test(){
    return {'one':1,'two':2,'three':3};
};
let {one:one_test,two:two,three:three} = test();
console.log(one_test,two,three);//1 2 3
文末福利:

福利一:前端,Java,产品经理,微信小程序,Python等资源合集大放送:https://www.jianshu.com/p/e8197d4d9880
福利二:微信小程序入门与实战全套详细视频教程:https://www.jianshu.com/p/e8197d4d9880



作者:喜欢坑队友的程序员
链接:https://www.jianshu.com/p/5f3f8eaacc4f
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

转载于:https://www.cnblogs.com/wangting888/p/9701680.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值