April 2025posted on 04.25.2025JSON.stringify replacer parameter JSON.stringify has an optional second parameter replacer that can recursively transform properties during the stringify process. The replacer parameter can be a function or an array: JSON.stringify({ name: 'Peter', til: true }, ['name']); // '{"name":"Peter"}' function replacer(key, value) { if (key === 'name') { return 'Mekhaeil'; } return value; } JSON.stringify({ name: 'Peter', til: true }, replacer); // '{"name":"Mekhaeil","til":true}' No reactions yet
JSON.stringify replacer parameter
JSON.stringifyhas an optional second parameter replacer that can recursively transform properties during the stringify process.The
replacerparameter can be a function or an array: