zoukankan      html  css  js  c++  java
  • js for循环,会遇到undefined

    node2:/var/www/html/js#
    node2:/var/www/html/js#cat h23.js
    var narr=['a','b','c','d','e'];
    console.log(narr);
    for (var j=0;j<narr.length;j++){
       console.log(j+'=>'+narr[j]);
    };
    
    console.log(narr);
    for (var j=0;j<narr.length;j++){
       console.log(j+'=>'+narr[j]);
       if (narr[j] == 'c'){
             //narr.splice(j,1);
             delete narr[j];
       };
    };
    console.log(narr);
    for (var j=0;j<narr.length;j++){
       console.log(j+'=>'+narr[j]);
    };
    
    
    
    (5) ["a", "b", "c", "d", "e"]0: "a"1: "b"3: "d"4: "e"length: 5__proto__: Array(0)
    h23.js:4 0=>a
    h23.js:4 1=>b
    h23.js:4 2=>c
    h23.js:4 3=>d
    h23.js:4 4=>e
    h23.js:7 (5) ["a", "b", "c", "d", "e"]0: "a"1: "b"3: "d"4: "e"length: 5__proto__: Array(0)
    h23.js:9 0=>a
    h23.js:9 1=>b
    h23.js:9 2=>c
    h23.js:9 3=>d
    h23.js:9 4=>e
    h23.js:15 (5) ["a", "b", empty, "d", "e"]0: "a"1: "b"3: "d"4: "e"length: 5__proto__: Array(0)
    h23.js:17 0=>a
    h23.js:17 1=>b
    h23.js:17 2=>undefined
    h23.js:17 3=>d
    h23.js:17 4=>e
    
    
    会遇到undefined问题
  • 相关阅读:
    Git远程库
    Git的使用
    如何利用IO流复制文件
    Lambda表达式
    Lambda表达式的标准格式
    线程池的使用步骤
    解决线程安全的三个方法
    多线程
    位运算
    如何用javadoc生成java帮助文档
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348733.html
Copyright © 2011-2022 走看看