How to replace values in a string, in JS

JavaScript: How to replace values in a string, in JS

You can use the replace() method to replace parts of a string with something. Here is an example:

  1.             let some_string = "Hello, world";
  2.              console.log(some_string.replace("world", "everyone"));

Hello, everyone
webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about How to replace values in a string, in JS

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the JavaScript language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to see all of the options for an artisan command?

How to remove .php from the end of URLs with .htaccess

How to set the Expires header in .htaccess

How to find an item by Primary Key in Eloquent, or throw a ModelNotFoundException exception if it isn't found?

How to hide directory listing in .htaccess?

How do you run a PHP script from the command line?

How to set up an alias to map one directory to another destination

How to hide the server signature (hide Apache info) from HTTP headers with .htaccess

How to add a name prefix to all routes in a group?

How to set infinite execution time in a PHP script