I have a function that takes separately the x and y values of a vector, say vector = (a,b), in which case the x value would be vector.x (yielding a number a), and the y value vector.y (or b).
However, I have a bunch of such vectors, and they don't follow any specific pattern, so I want to enter them manually in an array or matrix, such as array = [(a,b), (c,d), (e,f)] and then control which one of the vectors is supplied to the function at each moment with a slider.
For instance, sliding to the right one step would activate the vector (c,d), and both c and d would be fed into the function.
I know that an array can be entered as [[a,b], [c,d], [e,f]] and I can call e for instance as array[2][0], but the function is set up to use the syntax vector.x and vector.y. I see how easy it would be to just change the function, but I am curious how I can manually create this vector manually, and then control it with a slider from 0 to 2 at integer increments.
just map them:
const array = [['a','b'], ['c','d'], ['e','f']]
const transformed = array.map(([x,y]) => ({x,y}))
console.log(transformed)
For the vector object:
const array = [['a','b'], ['c','d'], ['e','f']]
const transformed = array.map(([x,y]) => (createVector(x, y)))
console.log(transformed)