# How to get Area of This Curve?

I would Like to calculate the area of The curve using the code `eval(array2.join('+')).toFixed(2);` but the result was not correct I don’t know if this code valid in this case .

here is the code

``````const vertices = [];
const array1 = [];
const array2 = [];
for ( let i = 0; i < 50; i ++ ) {
for ( let j = 0; j < 50; j ++ ) {
const y =formula(i,j);
vertices.push( new THREE.Vector3(i, y, j) );
}}
for ( let x = 0; x < 49; x ++ ) {
for ( let y = 0; y < 49; y ++ ) {
var area1=new THREE.Triangle(vertices[y+50*x],vertices[y+50*x+51],vertices[y+50*x+50]).getArea();
var area2=new THREE.Triangle(vertices[y+50*x],vertices[y+50*x+51],vertices[y+1]).getArea();
array1[y+49*x]=area1;
array2[y+49*x]=area2;
document.getElementById('Areacustom').value=(eval(array1.join('+'))+eval(array2.join('+'))).toFixed(2);
}}
``````

I used The function f(x,y)=x to test the code but gave this result as shown in the picture.

Above all, consider changing:

Into:

``````const result = array2.reduce((total, next) => total + next, 0.0);
const resultAsString = result.toFixed(2);
``````
1 Like