Reference setValue()

setValue()

Sets the value at the specified index of the vector.

This method allows you to change a specific component of the vector by providing its index and the new value you want to set. Think of the vector as a list of numbers, where each number represents a different direction (like x, y, or z). The index is just the position of the number in that list.

For example, if you have a vector with values [0, 20, 30], and you want to change the second value (20) to 50, you would use this method with index 1 (since indexes start at 0) and value 50.

Examples

Syntax

setValue(index, value)

Parameters

index
Number: The position in the vector where you want to set the new value.
value
Number: The new value you want to set at the specified position.
Notice any errors or typos? Please let us know. Please feel free to edit src/math/p5.Vector.js and open a pull request!

Related References