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....
Because arrays in JS are reference values, so when you try to copy it using the = it will only copy the reference to the original array and not the value of the array. To create a real copy of an array, you need to copy over the value of the array under a new value variable.
Using the indexOf() method In this method, what we do is that we compare the index of all the items of an array with the index of the first time that number occurs. If they don't match, that implies that the element is a duplicate. All such elements are returned in a separate array using the filter() method.
To remove the duplicates from an array of objects:Use the Array. filter() method to filter the array of objects. Only include objects with unique IDs in the new array.
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); })
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) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With