es6 函数箭头

1.数组方法

 let shut = [1, 2, 3, 5, 6, 7, 8, 9, 10]
shut.sort((n1, n2) => {
    return n1 - n2;
})
alert(shut)

2.函数用法

  let arr = (a) => {
    return a * 2;
}
alert(arr(14))

3.函数参数

let arr1 = [1,2,3]
let arr2 = [4,5,6]
let arr = [...arr1,...arr2]
console.log(arr)

4.赋值用法

  let [{ a, b }, [n1, n2, n3], num, arr] = [{ a: 1, b: 2, }, [4, 5, 6], 8, 'srt']
    console.log(a, b, n1, n2, n3, num, arr)

5.平均数

      let arr = [12, 3, 56, 45454]
let srt = arr.reduce((a, b, c) => {
    if (c != arr.length - 1) {
        return a + b;
    } else {
        return (a + b)
    }
})
alert(srt)

你可能感兴趣的:(es6 函数箭头)