
…扩展法是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://m.ipkd.cn/webs_2512.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

Amazon Translate官方网址入口
划词AI助手
讯飞星火认知大模型:大讯飞推出的一款新一代认知智能大模型
Oldswf小游戏:一个专门提供经典Flash小游戏的平台
SEO公司有哪些优点值得选择?
一款专为科研人员设计的AI深度文献检索工具——Ai2 PaperFinder