Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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 下面的.forEach语句做什么?_Javascript_Three.js - Fatal编程技术网

Javascript 下面的.forEach语句做什么?

Javascript 下面的.forEach语句做什么?,javascript,three.js,Javascript,Three.js,下面的两个forEach语句是做什么的?“col”是数组的内置属性吗 var width = data.length, height = data[0].length; data.forEach(function(col){ col.forEach(function(val){ geometry.vertices.push(new THREE.Vector3(val.x,val.y,val.z)) colors.push(getColor(2.5,

下面的两个forEach语句是做什么的?“col”是数组的内置属性吗

var width = data.length, height = data[0].length;
    data.forEach(function(col){
    col.forEach(function(val){
        geometry.vertices.push(new THREE.Vector3(val.x,val.y,val.z))
        colors.push(getColor(2.5,0,val.z));
    });
    });
如果需要某些早期代码:

var data = new Array();
    for(var x=BIGIN;x<END;x++){
    var row = [];
    for(var y=BIGIN;y<END;y++){
        z = 2.5*(Math.cos(Math.sqrt(x*x+y*y))+1);
        row.push({x: x, y: y, z: z});
    }
    data.push(row);
    }
var data=new Array();
for(var x=BIGIN;x迭代数组,就像
for
循环一样

array.forEach(function( indice ) {});
data
是一个数组
col
是第一个
forEach
传递的参数,因此第二个
forEach
迭代
数据
中的数组

在创建
数据的代码中也很明显

var data = []; // data is an array
...
var row = [];  // row is an array
for(var ...){
    // do stuff
}
data.push(row); // put one array inside the other
然后进行迭代

data.forEach(function(col){ // <- col is passed as the argument
    col.forEach(function(val){
        // do stuff
    });
});
data.forEach(函数(col){//参见此处