storing coordinates in array in javascript

前端 未结 4 2007
别那么骄傲
别那么骄傲 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 08:07

    The push method would do the job:

    var arr = new Array();

    arr.push({ x : x_coordinate, y : y_coordinate });

    You can then access them by using

    arr[0].x (gives the x coordinate)

    and

    arr[0].y (gives the y coordinate).

    Hope it helps.

提交回复
热议问题