JS的扩展运算符(...)


 1 // 扩展运算符(...)
 2 let a = [1,2,3,4]
 3 let b = [5,6,7,8]
 4 let c = [9,10,11,12]
 5 let d = '1'+'2'+'3'
 6 // 将数组转为一个参数序列
 7 console.log(...a)
 8 // 将b添加在a的尾部
 9 a.push(...b)
10 console.log(a)
11 // 合并数组
12 console.log([...b,...c])
13 // 结合Math方法求最大值
14 console.log(Math.max(...a))
15 // 将字符串转为数组
16 console.log([...d])
17 // Array.of将一组值或字符串转为数组
18 console.log(Array.of('3',4,5))
19 // find()找到符合条件的成员,value为当前值,index为所在索引,arr为原数组
20 a.find((value,index,arr)=>{
21     if(value < 4) console.log(value,index)
22 })
23 // findIndex()找到符合条件的成员,value为当前值,index为所在索引,arr为原数组
24 a.findIndex((value,index,arr)=>{
25     if(value < 4) console.log(value,index)
26 })

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM