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

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


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 install and use jpegoptim on Linux CentOS

How to convert a string to an array of it's characters in PHP?

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

How to group a SQL statement in brackets/parenthesis

How to select all rows for a certain month (or day, year or time), using Eloquent

Point all requests to one PHP file

How to do comments in Blade files?

Set PHP config Variables (like ini_set) with .htaccess

How to find the index of a value in an array in JS?

What is WordPress default Apache .htaccess rules?