ES6 扩展运算符:...

2021-01-13  本文已影响0人  安徒生1997

// let arr=['jinan','beijing','tianjin'];

// console.log(arr);

// ['jinan','beijing','tianjin']  -> ...arr  -> jinan beijing tianjin

// console.log(...arr);

// 1,2,3,4,5  -> ...a  -> [1, 2, 3, 4, 5]

// function show(...a){

// console.log(a)

// };

// show(1,2,3,4,5);

// sort();sort() 方法用于对数组的元素进行排序

// show(1,9,8,3,2)  -> ...a{return a.sort();}  -> [1, 2, 3, 8, 9]

// function show(...a){

// return a.sort();

// };

// console.log(show(1,9,8,3,2));

// ...[1,9,7]  -> 1 9 7

// function show(a,b,c){

// console.log(a,b,c);

// };

// show(...[1,9,7]);

// a,b,...c  ...必须放到最后

// (1,2,3,4,5)  -> a,b,...c  -> 1 2 [3, 4, 5]

// function show(a,b,...c){

// console.log(a,b);

// console.log(c);

// };

// show(1,2,3,4,5);

// 字符串转数组

// ["a", "-", "b", "-", "c"]

// let str='a-b-c';

// let arr=Array.from(str);

// console.log(arr)

上一篇 下一篇

猜你喜欢

热点阅读