Javascript 下面的.forEach语句做什么?
下面的两个forEach语句是做什么的?“col”是数组的内置属性吗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,
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){//参见此处