var points = [{ x: 75, y: 25},{ x: 75+0.0046, y: 25}];
Comment pourrais-je itérer à travers cela. Je veux imprimer les valeurs x et y en premier, puis en 2e et ainsi de suite ….
Utilisez la méthode Array#forEach
pour l’itération du tableau.
var points = [{ x: 75, y: 25 }, { x: 75 + 0.0046, y: 25 }]; points.forEach(function(obj) { console.log(obj.x, obj.y); })
var points = [{ x: 75, y: 25},{ x: 75+0.0046, y: 25}]; //ES5 points.forEach(function(point){ console.log("x: " + point.x + " y: " + point.y) }) //ES6 points.forEach(point=> console.log("x: " + point.x + " y: " + point.y) )
Vous pouvez utiliser for..of
loop.
var points = [{ x: 75, y: 25},{ x: 75+0.0046, y: 25}]; for (let point of points) { console.log(point.x, point.y); }