I want to add more elements dynamically to an array that has a named structure, I have (this works):
var v = [{
x: 0,
y: 0
}];
It initializes the structure with 1 element with 2 values, but, I want to add more elements later in the page, something like:
v.x.push(2); // something like this would insert a new element and give value of 2 to x of the new element.
Can anyone help me with this, using pure JavaScript? Thanks.
z: 0?const pushCoord = (coordArr, coordObj = {}) => [...coordArr, { x: 0, y: 0, ...coordObj}]- this handles case if there is only one coordinate given and defaults other to 0 (or if there are no arguments given)