0

I'm trying to replace a placeholder in a string I'm generating.

My string looks like this:

 var s = 'module("SlapOS UI Basic Interaction"); ' +
         'asyncTest( "${base_url}", function() { ' +
         ' expect( __number__ ); ' +
         ' ok(testForElement("div#global-panel"), "element present");' +
         ' start(); })';

And I want to replace __number__.

I can get the index correctly like so:

 s.indexOf("__number__");

but replacing does not work...

 s.replace("__number__", "1");

Question:
What am I doing wrong here? Makes no sense to my why it does not work.

frequent
  • 27,643
  • 59
  • 181
  • 333

1 Answers1

2

The replace method does not modify the existing string. It returns a new one.

var result = s.replace("__number__", "1");
Bryan
  • 2,870
  • 24
  • 39
  • 44
Denys Lieu
  • 260
  • 2
  • 9