Skip to content
Advertisement

Execute f-string in function

I have a

JavaScript

and want to replace all tokens starting with

JavaScript

with a new token

JavaScript

I wrote a function:

JavaScript

If I execute the lines separately it works. But the function itself doesn’t work.

JavaScript

I’d expect

JavaScript

How can I “exec” f-string in a function?

Advertisement

Answer

You are overcomplicating this. Simply reassign x:

JavaScript

But it’s probably easier to rewrite the function similar to the following:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement