ES6中的扩展运算符

扩展运算符(...)将一个数组转化为参数序列,通常与函数一起使用,show(...['judy','girl'])。

数组合并:[...arr1,...arr2,...arr3]

字符串转字符数组:[..."hello"]--------------["h","e","l","l","o"]

将实现Iterator接口的对象转化为真正的数组:[...nodelist],这里的nodelist是一个类似于数组的nodelist对象.

Generator 函数:该函数执行后返回一个遍历器对象,拓展运算符也可将其转化为数组。

let a =function*(){
    yield 3;
    yield 4;
    yield 5;
    return 6;
};
console.log([...a()]);              //[3,4,5]

猜你喜欢

转载自www.cnblogs.com/150536FBB/p/11599548.html