Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用于创建表头的Js foreach_Javascript_Foreach - Fatal编程技术网

Javascript 用于创建表头的Js foreach

Javascript 用于创建表头的Js foreach,javascript,foreach,Javascript,Foreach,我使用下面的代码动态创建表标题 var tableHeaders = "<th>No</th>"; tableHeaders += "<th>Devices</th>"; tableHeaders += "<th>Users</th>"; response.forEach(function(entry){ ent

我使用下面的代码动态创建表标题

var tableHeaders = "<th>No</th>";
            tableHeaders += "<th>Devices</th>";
            tableHeaders += "<th>Users</th>";
    response.forEach(function(entry){ 
                            entry.chartElements.forEach(function(childrenEntry) {
                              tableHeaders += "<th>" + childrenEntry.label + "</th>";
                            });
                        });

它实际上是在进入forEach吗?您验证了吗?是的,它正在进入forEach。控制台中有错误吗?是
response
一个数组还是仅仅一个对象?response是一个对象数组,每个对象包含另一个数组,即chartElements。控制台中没有错误。
0: Object
      chartElements: [{count: 1
                     label: "Lollipop"
                     totalCount: 0}]
      deviceCount: 1
      deviceName: "Lenovo"

1: Object
    chartElements: [{count: 1
                     label: "Lollipop"
                     totalCount: 0}]
      deviceCount: 1
      deviceName: "Zenfone"
2: Object
    chartElements: [{count: 1
                     label: "Lollipop"
                     totalCount: 0}]
      deviceCount: 1
      deviceName: "MotoG"
3: Object
    chartElements: [{count: 1
                     label: "Lollipop"
                     totalCount: 0}]
      deviceCount: 1
      deviceName: "Nexus5