gaurav singh gaurav singh - 1 month ago 8
jQuery Question

How to Iterating over arrays and objects in JavaScript

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


how would i iterate this.
I want to print first x and y value 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);
})