replace(value1, value2)
Replaces all cells containing value1 — matched by identity (===) — with value2. The two-arg sibling of replace(value), which retargets every filled cell instead.
Example
(click on any cell to replace all cells with the same value with a 🙈; press any key to reset)
Note
value1is matched by identity (===), so all cells meant to be caught must share the same instance — the classic gotcha with object values like colors; see the identity note in fill(value) and strict search. The example dodges it by storing each color once and reusing the variable.
Syntax
replace(value1, value2)
Parameters
| Param | Description |
|---|---|
value1 |
Any: A valid JavaScript value |
value21 |
Any: A valid JavaScript value |
What this page's examples use
- p5.quadrille
drawQuadrillecreateQuadrillecellLengthmouseRowmouseColrandreadreplace- p5.js
createCanvasbackgroundcolor
Names the analysis can prove are called, and the line each one is documented on. Local variables and members of an unknown receiver are left out.