在javascript中显示嵌套数组

时间:2015-10-13 22:46:13

标签: javascript

 def check(self, data):
        dataarr = np.asarray(data)
        extmax = argrelextrema(dataarr, np.greater)
        extmin = argrelextrema(dataarr, np.less)

如何在新行中显示大多数内部数组元素,如联系人号码?

3 个答案:

答案 0 :(得分:0)

var people =[
          ["nan","30","female", ["4545345454", "4324324324"]], 
          ["ban","35","male", ["4324234234", "7576343243"]],
          ["san", "38","male", ["3242342343", "3423423434"]]
     ];
//var k=0;
// document.write(people[0][3][0]);
for(var row=0;row<people.length;row++){
 document.write("<h2> Person" +(row+1)+"</h2>");
 for(var col=0; col<people[row].length-1; col++){
    document.write(people[row][col] +"<br>");


 }
 for(var pcol=0; pcol<people[row][3].length; pcol++){
    document.write(people[row][3][pcol] +"<br>");


 }

}

你需要循环手机阵列

答案 1 :(得分:0)

如果您希望对象中的其他元素也可能是数组,则可以动态执行此操作:

function printArray(array) {
    for (var key in array) {
        if (typeof(array[key]) === "object") {
            printArray(array[key]);
        } else {
            document.write(array[key] + "<br>");
        }
    }
}

for (var i = 0; i < people.length; i++) {
    document.write("<h2> Person" +(i+1)+"</h2>");
    printArray(people[i]);
}

查看整个对象结构,查找类型为object的元素,并以递归方式查看这些对象。

答案 2 :(得分:0)

如果深度未知,您可以使用递归

var people = [
  ["nan", "30", "female", ["4545345454", "4324324324"]],
  ["ban", "35", "male", ["4324234234", "7576343243"]],
  ["san", "38", "male", ["3242342343", "3423423434"]]
];

var dump = function(o) {
  if (o instanceof Array) {
    for (var i = 0, l = o.length; l > i; i++)
      dump(o[i]);
    return;
  }
  document.write(o + "<br/>");
};

dump(people);