How to replace the second occurrence of a string in javascript
It's because you never use the result returned by the replace
function.
Here's the corrected code:
const text = 'BLABLA'
let t = 0
const result = text.replace(/B/g, match => ++t === 2 ? 'Z' : match)
console.log(result)