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
  • 相关阅读:
    容斥原理
    泰勒展开
    初等微积分
    粒子群优化(微粒群算法)
    生成函数
    FFT例题
    图论例题
    线段求交
    期望小小结
    [Violet]天使玩偶/SJY摆棋子
  • 原文地址:https://www.cnblogs.com/luguankun/p/13742777.html
Copyright © 2011-2022 走看看