Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
176
rated 0 times [  178] [ 2]  / answers: 1 / hits: 36656  / 14 Years ago, sun, august 29, 2010, 12:00:00

How to create point object containing x,y and creating its array?
so that i can loop over those points, add/remove points dynamically.


More From » javascript

 Answers
54
var points = [{x:45, y:64}, {x:56, y:98}, {x:23, y:44}];
var len = points.length;
for(var i = 0; i < len; i++) {
alert(points[i].x + ' ' + points[i].y);
}

// to add more points, push an object to the array:
points.push({x:56, y:87});


Demo: http://jsfiddle.net/gjHeV/


[#95768] Thursday, August 26, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kadinl

Total Points: 321
Total Questions: 117
Total Answers: 103

Location: Nepal
Member since Mon, Jan 4, 2021
3 Years ago
;