es6 语法专栏

  1. ES6字符串扩展方法,字符串新方法  includes()  startwidth()   endwidth() 三个方法都支持第二个参数,表示开始搜索的位置;
    
    let str = 'Hello world!';
    
    console.log(str.includes('o')) // true ----表示是否找到了参数字符串;类似ES5 indexOf()
    console.log(str.startsWith('Hello')) // true ----表示参数字符串是否在原字符串的头部;
    console.log(str.endsWith('!')) // true ----表示参数字符串是否在原字符串的尾部;

  2. es6新增的数组方法  forEach()  filter()   map()  reduce()
    1)forEach() 遍历数组无返回值,不改变原数组,相当于for循环。
    2)filter: 用于过滤,相当于循环并进行if判断,返回符合条件的项组成的新数
    const arr = [1,2,3,4,5];
    const newArr = arr.filter((item) => item>3 );// newArr = [4,5]

     3)map:遍历数组,返回一个新数组,不改变原数组

    const arr = [1,2,3,4,5];
    const newArr = arr.map((item) => item+1 );// newArr = [2,3,4,5,6]

    4)some :循环,判断有没有符合的项,符合后结束循环,返回boolean类型

    const arr = [1,2,3,4,5];
    const test1 = arr.some((item) => item>3 );// test1 = true
    const test2 = arr.some((item) => item>6 );// test2 = false
    5)reduce() 汇总 一堆出来一个(用于比如,算个总数,算个平均),reduce让数组的前后两项进行某种计算,然后返回其值,并继续计算,不改变原数组,返回计算的最终结果,如果不给定初始值,则从数组的第二项开始遍历
    arr.reduce(callback(accumulator, currentValue[, index[, array]])[, initialValue]) ,第一个参数回调函数,第二个参数初始值
    求和:
    //第一种给定初始值
    var arr = [1, 3, 5, 7];
    // 原理: 利用reduce特性 prev初始值设置0 并把函数的返回值再次带入函数中
    var sum = arr.reduce(function (tmp, item,index) { // prev 初始为0 以后则为函数返回的值
        console.log(tmp,item,index);
        //  0 1  0
        //  1 3  1
        //   4 5  2
        //   9 7  3
        return tmp + item; // 数组各项之间的和
    }, 0);
    
    console.log(sum); //16
    //第二种不给初始值
    var arr2 = [1, 3, 5, 7]
    var result = arr2.reduce(function (tmp, item, index) {
        //tmp 上次结果,item当前数,index次数1开始
        console.log(tmp, item, index)
        //1 3 1 
        // 4 5 2 
        // 9 7 3 
        return tmp + item;
    })
    
    console.log(result,)   //16
    求平均值
    var arr = [1, 3, 5, 7]
    
    var result = arr.reduce(function (tmp, item, index) {
    
      console.log(tmp,item,index);
    
      // 1 3  1
    
     //  4 5  2
    
     //  9 7  3
    
        if (index != arr.length - 1) { // 不是最后一次
    
            return tmp + item
    
        } else {
    
            return (tmp + item)/arr.length
    
        }
    
    })
    
    console.log(result,'[[[u99')  // 平均值  4
     

  3. .ES6对象 新特性:assign 浅拷贝源对象可枚举属性

  4. 数组方法   reduce(),  silce 和splice区别
    splice()实现数组的删除 插入 替换,输出[]
    mapfilterslice返回一个新数组,find返回一个元素,而reduce返回一个减小的值,且这些都不会改变原数组。
    != 返回同类型值比较结果。
    !== 不同类型不比较,且无结果,同类型才比较

    1).map() 是对数组的每个元素都遍历一次,同时返回一个新的数组,返回数组的长度和原始数组长度一致。
    2).filter() 是创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素。
    3).find() 返回符合测试条件的第一个数组元素值,如果没有符合条件的则返回 undefined。
    4).reduce() 可以直观的返回数组里面指定的一个值或者对象
    array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
    function(total,currentValue, index,arr) 必需。用于执行每个数组元素的函数。
    total 必需。初始值, 或者计算结束后的返回值。
    currentValue 必需。当前元素
    currentIndex 可选。当前元素的索引
    arr 可选。当前元素所属的数组对象。
    initialValue 可选。传递给函数的初始值。如果没有在这定义初始值,那么初始值将变成数组中的第一项,而 currentVal 将从数组的第二项开始。
    5)slice(start,end) 用于截取
    start:开始位置的索引 end:结束位置的索引(但不包含该索引位置的元素),如果没有第二个参数,默认截取到最后一位。
    6)splice具有删除,插入,替换的功能
    1:删除的功能
    splice(index,count) index:开始位置的索引 count:要删除元素的个数
    返回:包含被删除元素的数组对象
    2:插入功能
    splice(index,0,插入的项) index:插入元素的索引值,返回:[]
    3:替换功能
    splice(index,num,value) index:开始的索引位置
    num:删除项的数(如果num为0,就是插入功能)
    value:插入的值 返回:包含被删除的元素的数组对象

  5. 框架  react状态管理   hooks 监听改变状态时用哪个

  6. webpack做哪些配置 loader和 plugin有哪些
    webpack核心 entry output  module  chunk  loader plugin
    loader用来识别特定文件供webpack进行转换后输出文件:babel-loader  postcss-loader   file-loader  url-loader style-loader  css-loader  sass-loader  vue-loader
    plugin是补充一些webpack本来没有功能插件:HtmlWebpackPlugin  cleanWebpackPlugin打包自动删除上次打包文件

  7. 正则表达式
    \d  匹配数字
    \w 匹配任意数字 字母 下划线 A~Z,a~z,0~9,_ 中任意一个

  8. 数组去重

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值