js怎么遍历json二维数组
发布网友
发布时间:2022-05-06 15:02
我来回答
共1个回答
热心网友
时间:2022-07-01 02:49
<script type="text/javascript">
var data = [{ id: 0, chiild: [{ msg: '111' }, { msg: '222'}] }, { id: 3, chiild: [{ msg: '444' }, { msg: '555'}] }, { id: 2, chiild: [{ msg: '467' }, { msg: '58912'}]}];
var str = "";
var strmsg = "";
for (var i = 0; i < data.length; i++) {
str += data[i].id;
for (var j = 0; j < data[i].chiild.length; j++) {
strmsg += data[i].chiild[j].msg;
}
}
alert(strmsg);
</script>