zoukankan      html  css  js  c++  java
  • es6之数组方法

    //兼容插件 babel-polyfill

    values()等存在兼容问题,需要加载babel-polyfill插件

    .keys()  获取数组的key值

    .values()  获取数组的value值

    .entries() 获取key,value的值

    .copyWithin(); 可传三个参数,第一个是指替换的位置,第二个只是替换的值开始的位置,第三个指替换的值结束的位置

     console.log([1,2,3,4,5].copyWithin(0,3,4))
    //[4,2,3,4,5]
    

    find查找第一个符合条件的数

    //查找
        console.log([1,2,3,4,5,6].find(function(item){
            return item>3  //4
        }));
        console.log([1,2,3,4,5,6].findIndex(function(item){
            return item>3  //3
        }));
    

    includes //查找具体的值

    console.log("number",[1,2,NaN].includes(NaN)) //true

    字符串转化成数组

    Array.of

    let arr=Array.of(3,4,7,9,11);
        console.log('arr=',arr);  //arr=[3, 4, 7, 9, 11]

     Array.from  将集合转化成数字、当有第二个参数时有map的功能 

      console.log(Array.from([1,3,5],function(item){
            return item*2;  //[2,6,10]
        }));
    

    Array.fill() 填充数组的功能

    console.log("fill-7",[1,"a",undefined].fill(7));  //[7,7,7]
    console.log("fill-7",[1,"a",undefined].fill(7,1,3));  //[1,7,7]
    fill 第一个参数是值被替换成的值,第二个参数是起始位置,第三个参数只是结束位置,不包括结束位置

        

  • 相关阅读:
    rsync使用
    文件系统、mkdir、touch、nano、cp笔记
    man/ls/clock/date/echo笔记
    Python之路,Day2
    Python之路,Day1
    自动化部署nginx负载均衡及监控短信报警
    NO.11天作业
    Tiny C Compiler简介-wiki
    stm32中使用cubemx配置freertos的信号量大小
    c99的新功能
  • 原文地址:https://www.cnblogs.com/karila/p/7865729.html
Copyright © 2011-2022 走看看