storing coordinates in array in javascript

前端 未结 4 2015
别那么骄傲
别那么骄傲 2021-02-04 07:37

I want to store coordinates into an array in javascript, I am new to javascript and do not have an idea how to do it.

Any help would be appreciated.

4条回答
  •  情深已故
    2021-02-04 07:45

    Well, let's say we make it simple, you want to store coördinates, so we have x and y:

    function coordinate(x, y) {
        this.x = x;
        this.y = y;
    }
    

    This is how you create Objects in javascript, they act like functions. With this function you can create your coordinates. Then all you need to do is create an array:

    var arr = new Array();
    arr.push(new coordinate(10, 0));
    arr.push(new coordinate(0, 11));
    

    That's it basically

提交回复
热议问题