gaurav singh gaurav singh - 1 month ago 4
Javascript Question

How to iterate over arrays and objects in JavaScript

var points = [{ x: 75, y: 25},{ x: 75+0.0046, y: 25}];


How would I iterate through this.
I want to print x and y value first, then 2nd and soo on....

Answer

Use Array#forEach method for array iteration.

var points = [{
  x: 75,
  y: 25
}, {
  x: 75 + 0.0046,
  y: 25
}];

points.forEach(function(obj) {
  console.log(obj.x, obj.y);
})

Comments