zoukankan      html  css  js  c++  java
  • 稀疏数组和密集数组的异同

     稀疏数组含有空缺,
     密集数组,每个位置都有元素(undefined也算是元素)
    例如:
     // 1.稀疏数组
        let ch = [,,3]
        // 2.密集数组
        let ci = [undefined,undefined,3]
    区别:
     // 3.区别:
        // (1) in 操作符找index
        console.log(0 in ch ); // false 找不到这个index
        console.log(0 in ci ); // true 
        // (2) 使用forEach遍历,稀疏数组跳过空缺,密集数组不会跳过undefined
        ch.forEach(v=>console.log(v)) // 3
        ci.forEach(v=>console.log(v)) // undefined undefind 3

    相同点:

        // 4.相同点:
        // (1) 上面两个数组的长度是相同的
        // (2) for遍历,得到一样的结果
        for(let i =0;i<ch.length;i++) console.log(ch[i]); // undefined undefind 3
        for(let i =0;i<ci.length;i++) console.log(ci[i]); // undefined undefind 3
  • 相关阅读:
    Directx
    apr库开发
    linux 上編譯apache
    数字信号处理---FFT
    C# Parallel用法
    C#线程同步--线程通信
    C#线程同步--限量使用
    C#线程安全类型
    C# Task用法
    C# ThreadPool类(线程池)
  • 原文地址:https://www.cnblogs.com/luguankun/p/13742777.html
Copyright © 2011-2022 走看看