Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an array of Points?

Tags:

javascript

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

like image 278
coure2011 Avatar asked Aug 29 '10 07:08

coure2011


People also ask

How do you point an array in Java?

The process begins by making a copy of the pointer that points to the array: int *ptr = A; // ptr now also points to the start of the array. This pointer points to the first element in the array. You can dereference that pointer to access the array element.

What is an array of OBJ?

An array of objects, all of whose elements are of the same class, can be declared just as an array of any built-in type. Each element of the array is an object of that class. Being able to declare arrays of objects in this way underscores the fact that a class is similar to a type.

How do you add an element to an array of elements?

JavaScript Array push() The push() method adds new items to the end of an array. The push() method changes the length of the array.


1 Answers

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/

like image 196
karim79 Avatar answered Oct 31 '22 15:10

karim79