JavaScript evaluator: replace backslash

  • 26 October 2021
  • 1 reply

Userlevel 6
Badge +3
  • Senior Technical Evangelist and Developer Advocate at Snowflake
  • 67 replies

Is there a more sophisticated way of removing backslash within a string? I've tried string.replace(/\\/g, ""), but that did not help.


Best answer by Dash 26 October 2021, 22:46

View original

1 reply

Userlevel 6
Badge +3

JavaScript replace returns a new string rather than modifying the string you call it on, so you need to do something like: 

records[i] = records[i]\\/g,"");

Note that if you are modifying field names rather than their values, you need to build a list of the old keys, a map of the new keys and their values, and then apply the changes. If you try to operate on the keys while looping through them, you'll get a ConcurrentModificationException