…扩展法是es6独有的语法,展开运算符在多个参数(用于函数调用)或多个元素(用于数组字面量)或者多个变量(用于解构赋值)的地方可以使用。
1、复制数组
const a = [1, 2, 3, 4, 5]; const c = [...a]; console.log(c); //(5) [1, 2, 3, 4, 5]
2、字符串转为数组
const name = 'china'; const nameArr = [...name]; console.log(nameArr); //(5) ['c', 'h', 'i', 'n', 'a']
3、合并数组
const a = [1, 2, 3]; const b = ['a','b']; const c = [4, 5]; console.log([...a, ...b, ...c]); //(7) [1, 2, 3, 'a', 'b', 4, 5] console.log([...c, ...a, ...b]); //(7) [4, 5, 1, 2, 3, 'a', 'b'] console.log([99, ...a, 24, ...b, ...c]); // [99, 1, 2, 3, 24, 'a', 'b', 4, 5]
上面是“es6语法中数组的使用方法(...展开符)”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_2512.html
workflows工作流
令人着迷的一只老虎ComfyUI工作流
城市里出现一只可爱的小生物ComfyUI工作流
1个可爱的白色短发女孩
一条赤壁龙从蛋中孵化出来ComfyUI工作流
一个穿着发光红色长袍的人
一群邪恶的小黄人ComfyUI工作流
在月球上穿着太空服的宇航员
文生图工作流:一幅海底睡莲,碧海蓝天comfyui工
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!