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)

edit, then run

Note

value1 is 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
  1. A plain function value2 is stored, not called — it becomes a per-cell display routine ({ row, col, options }) => { ... } (see options). To have a function evaluated per cell at replace time — a fresh object or a varied tile per cell — tag it: Quadrille.factory(({ row, col }) => new Object(...)). ↩
What this page's examples use
p5.quadrille
drawQuadrille createQuadrille cellLength mouseRow mouseCol rand read replace
p5.js
createCanvas background color

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.