Home > Web Front-end > JS Tutorial > body text

js parses json array object into two-dimensional array

不言
Release: 2018-03-31 14:31:31
Original
3766 people have browsed it

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;
}
Copy after login
</script>
相关推荐:
Copy after login
<a href="http://www.php.cn/js-tutorial-388752.html" target="_self">nodejs解析xml字符串为对象的实例</a><br><br>
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!