zoukankan      html  css  js  c++  java
  • ES6 的数组知识

    // json数组格式
    let json={
        // key:value
        '0':'nl',
        '1':'jun',
        '2':'ming',
        // length可见是json数组格式
        length:3
    }
    // 使用转换成数组的方法是Array.from()方法
    let arr=Array.from(json);
    console.log(arr);
    
    //这里看下Array.of方法的使用
    let arr1=Array.of(3,4,5,6);
    let arr2=Array.of('nl','jun');
    console.log(arr1);
    console.log(arr2);
    
    //find()实例方法(因为需要有了实例之后才能有这个方法来使用),用于查找数字或者字符串
    let arr3=[1,2,3,4,5,6,7,8,9];
    console.log(arr3.find(function(value,index,arr3){
        return value>5;
        // 如果返回undefined说明没有存在这样的值
    }));
    //fill
    let arr=['nl','jun','ming'];
    //1-3,替换掉了jun和ming
    arr.fill('web',1,3);
    console.log(arr);
    
    //for of循环,比for in直观
    let arr1=['mudan','juhua','guihua'];
    for(let item of arr1){
        console.log(item);
    }
    // 下面是输出下标
    for(let item of arr1.keys()){
        console.log(item);
    }
    // 下面是输出索引和值
    for(let item of arr1.entries()){
        console.log(item);
    }
    //但是我们要用数组把值提炼出来,才是我们想要的
    for(let [index,val] of arr1.entries()){
        console.log(index+':'+val);
    }
    
    // 这里说一下es6到es5的转换,我们可以借用工具babel或者gulp
    
    // 下面讲一下entries实例方法,entries()实例方式生成的是Iterator形式的数组
    let list=arr1.entries();
    console.log(list);
    // 下面工作中常用的手动循环(用next()手动跳转到下一个值)
    console.log(list.next().value);
    console.log('---------------------------');
    console.log(list.next().value);
    console.log('***************************');
    console.log(list.next().value);
    console.log('5555555555555555555555555555');
  • 相关阅读:
    Django_Setings
    python之event【事件】
    python之递归锁【Rlock】
    python之信号量【Semaphore】
    python的线程锁
    python的多线程和守护线程
    python的错误类型和异常处理
    python之ftp作业【还未完成】
    python之socket运用之传输大文件
    python之socket运用之执行命令
  • 原文地址:https://www.cnblogs.com/NeryXJ/p/9647664.html
Copyright © 2011-2022 走看看