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)
code
Quadrille.cellLength = 40;
let quadrille;
let tomato, lime, dodgerblue;
function setup() {
createCanvas(400, 400);
tomato = color('tomato');
lime = color('lime');
dodgerblue = color('dodgerblue');
reset();
}
function draw() {
background('black');
drawQuadrille(quadrille);
}
function mouseClicked() {
const row = quadrille.mouseRow;
const col = quadrille.mouseCol;
const value = quadrille.read(row, col);
quadrille.replace(value, '🙈');
}
function keyPressed() {
reset();
}
function reset() {
quadrille = createQuadrille(10, 10, 25, tomato);
quadrille.rand(25, lime).rand(25, dodgerblue);
}
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 |