Javascript help: changing an existing variable to another

Javascript help: changing an existing variable to another (variable name is “p_province” example is “Pennsylvania” to “us-pa”). I need to do this for each state. I’m relatively new to Javascript. Help!

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @cribbswh, welcome to the community!

Replacing text could be done using the JavaScript replace() method.

Seeing you want to do this for several different states I do, however, think it could make sense to define an array with all the names and codes you need, then write a little custom snippet looking up the respective code using the find() method instead. This will be much easier to edit in the future compared to several different replace methods.

Here’s an example workflow doing this for the format you have shared (us-pa):

Result:

Hope this helps!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.