zoukankan      html  css  js  c++  java
  • JavaScript数组多维数组的困惑

    //javascript中没有多维数组的概念
    var aa = new Array();
    aa[0] = 1;
    aa["tt"] = [0,1];//javascript在用负数,浮点数,(或布尔型,对象,其他值时),javascript会将它转换为一个字符串,用生成的字符串作为对象的属性名字,而不是定义了一个新的数组元素
    aa["bb"] = [2,3];
    //遍历数组中的所有属性,不仅仅遍历数组元素
    for(var i in aa){
    document.write(aa[i]);
    }
    document.write(aa.length);
    document.write(aa["tt"].length);

    var myArray=new Array(); 
    for(var i=0;i<10;i++){ 
    myArray[i]=new Array(); 
    myArray[i][0]=Math.floor(Math.random()*10); 
    myArray[i][1]=Math.floor(Math.random()*10); 
    myArray[i][2]=Math.floor(Math.random()*10); 
    myArray[i][3]=Math.floor(Math.random()*10); 
    myArray[i][4]=Math.floor(Math.random()*10); 
    myArray[i][5]=Math.floor(Math.random()*10); 
    myArray[i][6]=Math.floor(Math.random()*10); 
    myArray[i][7]=Math.floor(Math.random()*10); 
    myArray[i][8]=Math.floor(Math.random()*10); 

    myArray[10.2] = 11;
    myArray[9][9] = 22;
     
    myArray.sort(function(x,y){ 
    return(x[0]==y[0])?((x[4]==y[4])?(x[8]-y[8]):(x[4]-y[4])):(x[2]-y[2]) 
    });
    var count = 0;
    for(var i=0;i<myArray.length;i++)

    document.write(myArray[i].join(",")+"<br/>");
    for(var j = 0; j<myArray[i].length;j++){
    document.write(myArray[i][j]+"H"+"</br>"); 
    count++;
    }
    }
    document.write(myArray.length);//
    document.write(myArray[0].length);
    document.write(count);

  • 相关阅读:
    Python之黏包
    Python的subprocess模块
    (经典)TCP粘包分析
    python--数据类型bytes
    python socket编程
    Python之模块和包
    Memcache的客户端连接系列(二) Python
    Memcache的客户端连接系列(一) Java
    Stunnel客户端安装和配置
    分布式数据库中间件的实现原理介绍四:平滑扩容
  • 原文地址:https://www.cnblogs.com/Mygirl/p/2094270.html
Copyright © 2011-2022 走看看