Home  >  Article  >  Web Front-end  >  js parses json array object into two-dimensional array

js parses json array object into two-dimensional array

不言
不言Original
2018-03-31 14:31:313718browse

This article mainly shares with you part of the code about js parsing json array objects into two-dimensional arrays. I hope it can be helpful to friends in need

The key codes are as follows:


<script type="text/javascript">function zh(data)//用户将json数组对象解析成二维数组
{    var arr = [];    for(var i in data)
    {        arr[i] = [];        for(var j in data[i])
        {            arr[i].push(data[i][j]);
        }
    }    return arr;
}   
    
function addTable(getdata) {//将解析出来的二维数组显示    var p1=document.getElementById("p1");    var tab="<table border=&#39;1&#39;  width=&#39;200&#39; >";    var arr =[];    arr = zh(getdata);    for(var  i =0;i<arr.length;i++)
    {        tab+="<tr>";        for(var j = 0;j<arr[i].length;j++)
        {            tab+="<td>"+ arr[i][j] +"</td>";
        }        tab+="</tr>";
    }    tab+="</table>";    p1.innerHTML=tab;
}
</script>
相关推荐:
<a href="http://www.php.cn/js-tutorial-388752.html" target="_self">nodejs解析xml字符串为对象的实例</a><br><br>


The above is the detailed content of js parses json array object into two-dimensional array. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn